Elasticsearch 地理距离聚合
GET /_search
{
"size": 0,
"query": {
"bool": {
"filter": {
"geo_bounding_box": {
"location": {
"top_left": {
"lat": 40.8,
"lon": -74.
},
"bottom_right": {
"lat": 40.7,
"lon": -73.
}
}
}
}
}
},
"aggs": {
"restaurants": {
"geo_distance": {
"field": "location",
"origin": "40.7,-74",
"unit": "km",
"ranges": [
{
"from": 1,
"to": 10
},
{
"from": 10,
"to": 50
},
{
"from": 50,
"to": 100
},
{
"from": 100,
"to": 500
}
]
}
}
}
}
这个Elasticsearch查询语句使用了地理边界框来限制搜索范围,并使用地理距离聚合来分析该范围内各个距离区间内的文档数量。这对于开发者需要了解特定地理区域内基于距离的数据聚合场景非常有用。
评论已关闭