我在 Elasticsearch 中索引了一組位置(地理點)。有人可以建議一種使用elasticsearch地理查詢獲得最接近給定地理點的地理點的方法。我已經嘗試使用地理距離查詢,但是它需要我提供距離以指定以指定位置為中心的圓的半徑。我正在尋找一種替代解決方案,無論距離多遠,它都可以回傳最近的位置。建議表示贊賞。
uj5u.com熱心網友回復:
最好的方法是利用距離排序并檢索最近的地理位置:
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://www.uj5u.com/caozuo/320937.html
上一篇:彈性搜索:獲取價值>AVG的檔案
