我有一个数据库与以下样本。
"_index" : "python-address-test",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.0,
"_source" : {
"address" : "Graha Blok A",
"geohash6" : "qqgft0",
"location" : {
"lat" : -6.5881896,
"lon" : 106.747485
}
}
},
{
"_index" : "python-address-test",
"_type" : "_doc",
"_id" : "2",
"_score" : 0.0,
"_source" : {
"address" : "Graha",
"geohash6" : "qqgft0",
"location" : {
"lat" : -6.5895002,
"lon" : 106.7488968
}
}
},
{
"_index" : "python-address-test",
"_type" : "_doc",
"_id" : "3",
"_score" : 0.0,
"_source" : {
"address" : "Graha",
"geohash6" : "qqgft0",
"location" : {
"lat" : -6.5884867,
"lon" : 106.749212
预期退货应为,其中地址应唯一
{格拉哈A区,格拉哈}
我已经写了下面的代码,并能够得到最短距离的地址输入lat,long。但我无法得到唯一的地址。请告知
{ "size": 10,
"query": {
"bool": {
"must": {
"geo_distance": {
"distance": "1km",
"location": [
106.7485418,
-6.5875987
]
}
},
"filter": {"match" : {"geohash6" : "qqgft0"}}
}
},
"sort": [
"_score",
{
"_geo_distance": {
"location": {
"lat": -6.5875987,
"lon": 106.7485418
},
"order": "asc",
"unit": "m",
"distance_type": "plane"
}
}
]
}
1条答案
按热度按时间ee7vknir1#
您可以使用折叠查询,使每个地址仅显示1个结果:
https://www.elastic.co/guide/en/elasticsearch/reference/current/collapse-search-results.html
下面是示例代码:
Map
文件
查询
结果