Geo Bounds Aggregation

    一种度量聚合,用于计算包含字段的所有geo_point值的边界框。

    Example:

    1. PUT /museums
    2. {
    3. "mappings": {
    4. "properties": {
    5. "location": {
    6. "type": "geo_point"
    7. }
    8. }
    9. }
    10. }
    11. POST /museums/_bulk?refresh
    12. {"index":{"_id":1}}
    13. {"location": "52.374081,4.912350", "name": "NEMO Science Museum"}
    14. {"index":{"_id":2}}
    15. {"location": "52.369219,4.901618", "name": "Museum Het Rembrandthuis"}
    16. {"index":{"_id":3}}
    17. {"location": "52.371667,4.914722", "name": "Nederlands Scheepvaartmuseum"}
    18. {"index":{"_id":4}}
    19. {"location": "51.222900,4.405200", "name": "Letterenhuis"}
    20. {"index":{"_id":5}}
    21. {"location": "48.861111,2.336389", "name": "Musée du Louvre"}
    22. {"index":{"_id":6}}
    23. {"location": "48.860000,2.327000", "name": "Musée d'Orsay"}
    24. POST /museums/_search?size=0
    25. {
    26. "query" : {
    27. "match" : { "name" : "musée" }
    28. },
    29. "aggs" : {
    30. "viewport" : {
    31. "geo_bounds" : {
    32. "field" : "location", @1
    33. "wrap_longitude" : true @2
    34. }
    35. }
    36. }
    37. }

    @1: geo_bounds聚合指定用于获取边界的字段

    @2: wrap_longitude是一个可选参数,指定是否允许边界框与国际日期行重叠。默认值是true

    上面的聚合演示了如何计算具有商店类型商店的所有文档的位置字段的边界框

    上述聚合的响应:

    1. {
    2. ...
    3. "aggregations": {
    4. "viewport": {
    5. "bounds": {
    6. "top_left": {
    7. "lat": 48.86111099738628,
    8. "lon": 2.3269999679178
    9. },
    10. "bottom_right": {
    11. "lat": 48.85999997612089,
    12. "lon": 2.3363889567553997
    13. }
    14. }
    15. }
    16. }
    17. }