我在Elasticsearch中有一组位置(地理点)索引。有没有人能推荐一种方法,使用elasticsearch geo查询来获得离给定地理位置最近的地理位置。我已经尝试使用Geo Distance查询,但是它要求我提供距离来指定以指定位置为中心的圆的半径。我正在寻找一种替代解决方案,可以返回最近的位置,而不考虑距离。我们非常感谢您的建议。
发布于 2021-10-11 11:11:12
最好的方法是利用distance sorting并检索最近的地理位置:
GET my-index/_search
{
"size": 1, <--- return top 1
"sort" : [
{
"_geo_distance" : {
"location-field" : [-70, 40], <--- center location
"order" : "asc", <--- sorted by closest distance
"unit" : "km",
"mode" : "min",
"distance_type" : "arc",
"ignore_unmapped": true
}
}
],
"query" : {
"match_all" : {}
}
}
https://stackoverflow.com/questions/69520933
复制相似问题