【发布时间】:2017-12-31 10:45:18
【问题描述】:
我已经对名称进行了聚合,但地理距离排序无法正常工作。 我已经实现了聚合和距离计算。但我不知道如何计算桶距离值。 请建议我如何实现?
映射:-
PUT /museums
{
"mappings": {
"doc": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
}
数据值:
POST /museums/doc/_bulk?refresh
{"index":{"_id":1}}
{"location": "52.374081,4.912350", "name": "NEMO Science Museum"}
{"index":{"_id":2}}
{"location": "52.369219,4.901618", "name": "Museum Het Rembrandthuis"}
{"index":{"_id":3}}
{"location": "52.371667,4.914722", "name": "Nederlands Scheepvaartmuseum"}
{"index":{"_id":4}}
{"location": "51.222900,4.405200", "name": "Letterenhuis"}
{"index":{"_id":5}}
{"location": "48.861111,2.336389", "name": "Musée du Louvre"}
{"index":{"_id":6}}
{"location": "48.860000,2.327000", "name": "Musée d'Orsay"}
{"index":{"_id":7}}
{"location": "52.374081,4.912350", "name": "NEMO Science Museum"}
{"index":{"_id":8}}
{"location": "48.861111,2.336389", "name": "Musée du Louvre"}
弹性搜索查询:
POST /museums/_search?size=0
{
"query": {
},
"sort": {
"_geo_distance": {
"location": {
"lat": 52.3760,
"lon": 4.894
},
"order": "asc",
"unit": "km",
"distance_type": "arc"
}
},
"aggregations": {
"by_id": {
"terms": {
"field": "name.keyword",
"order": {
"_count": "asc"
},
"size": 20
},
"aggregations":{
"top":{
"top_hits":
{
"sort":{
"_geo_distance":{
"location":{"lat":19.143172,"lon":72.824966
}
}
}
}
}
}
}
}
}
上面的查询给出了结果,但没有按距离排序。
【问题讨论】:
标签: php sorting elasticsearch sphinx