更新时间:2023-11-10 11:21:58
您必须将_geo_distance
排序放在第一个位置,而不是第三个位置.就目前而言,对于与upgrade_sort
和has_siegel
具有相同值的那些文档,_geo_distance
排序将仅以升序对文档进行排序.尝试以下方法:
You have to put the _geo_distance
sort in the first position instead of the third one. As it stands, the _geo_distance
sort will only sort the docs in ascending distance order for those documents that have the same value for upgrade_sort
and has_siegel
. Try this instead:
{
"size": 30,
"from": 0,
"body": {
"query": {
"bool": {
"filter": {
"geo_distance": {
"distance": "100km",
"location": {
"lat": 49.449919468911,
"lon": 11.073560787681
}
}
}
}
},
"script_fields": {
"distance": {
"lang": "groovy",
"params": {
"lat": 49.449919468911,
"lon": 11.073560787681
},
"script": "doc['location'].distanceInKm(lat,lon)"
}
},
"sort": [
{
"_geo_distance": {
"location": {
"lat": 49.449919468911,
"lon": 11.073560787681
},
"order": "asc",
"unit": "km"
}
},
{
"upgrade_sort": {
"order": "desc"
}
},
{
"has_siegel": {
"order": "desc"
}
}
]
},
"fields": [
"_source",
"distance"
]
}