ES6.0.0官方参考指南翻译~指标聚合~Geo Bounds Aggregation

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计算的聚合


分享到:


相關文章: