Geo Bounds Aggregation
該指標聚合用於計算某字段中所有geo_point值的邊界框(矩形區域)。
示例:
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"}
POST /museums/_search?size=0
{
"query" : {
"match" : { "name" : "musée" }
},
"aggs" : {
"viewport" : {
"geo_bounds" : {
"field" : "location", #1
"wrap_longitude" : true #2
}
}
}
}
1 用於指定獲取邊界數據來源的字段
2 wrap_longitude是一個可選參數,用於指定是否允許邊界框與國際日期變更線(international date line)重合。默認為true。
針對業務類型為商店(shop)的所有文檔,上述聚合會計算所有商店所在的矩形區域。
其響應為:
{
...
"aggregations": {
"viewport": {
"bounds": {
"top_left": {
"lat": 48.86111099738628,
"lon": 2.3269999679178
},
"bottom_right": {
"lat": 48.85999997612089,
"lon": 2.3363889567553997
}
}
}
}
}
全部指標聚合,請參考
單值指標聚合
多值指標聚合
地理位置相關聚合
可執行Map-Reduce計算的聚合
閱讀更多 Java源 的文章