您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
elasticSearch的URI搜索-sort
发布时间:2021-09-02 16:17:03编辑:雪饮阅读()
在elasticSearch中对索引出来的结果集还可以进行排序,在URI搜索中通过sort来指定用于排序的字段及排序的方式,如:
请求正文:none
响应正文:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4,
"relation": "eq"
},
"max_score": null,
"hits": [
{
"_index": "schools",
"_type": "school",
"_id": "4",
"_score": null,
"_source": {
"name": "Saint Paul School",
"description": "ICSE Afiliation",
"street": "Dawarka",
"city": "Delhi",
"state": "Delhi",
"zip": "110075",
"location": [
28.5733056,
77.0122136
],
"fees": 5000,
"tags": [
"Good Faculty",
"Great Sports"
],
"rating": "4.5"
},
"sort": [
"4"
]
},
{
"_index": "schools",
"_type": "school",
"_id": "3",
"_score": null,
"_source": {
"name": "Central School",
"description": "ICSE",
"street": "West End",
"city": "Meerut",
"state": "UP",
"zip": "250002",
"location": [
28.9926174,
77.692485
],
"fees": 3500,
"tags": [
"fully computerized"
],
"rating": "4.5"
},
"sort": [
"3"
]
},
{
"_index": "schools",
"_type": "school",
"_id": "2",
"_score": null,
"_source": {
"name": "Saint Paul School",
"description": "ICSE Afiliation",
"street": "Dawarka",
"city": "Delhi",
"state": "Delhi",
"zip": "110075",
"location": [
28.5733056,
77.0122136
],
"fees": 5000,
"tags": [
"Good Faculty",
"Great Sports"
],
"rating": "4.5"
},
"sort": [
"2"
]
},
{
"_index": "schools",
"_type": "school",
"_id": "1",
"_score": null,
"_source": {
"name": "Central School4",
"description": "CBSE Affiliation",
"street": "Nagan",
"city": "paprola",
"state": "HP",
"zip": "176115",
"location": [
31.8955385,
76.8380405
],
"fees": 2004,
"tags": [
"Senior Secondary",
"beautiful campus"
],
"rating": "3.5"
},
"sort": [
"1"
]
}
]
}
}
这里是将schools中的文档都查询出来,然后通过_id字段字段降序排序。
关键字词:elasticSearch,URI,sort