geobounds-aggregation.asciidoc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. [[search-aggregations-metrics-geobounds-aggregation]]
  2. === Geo Bounds Aggregation
  3. A metric aggregation that computes the bounding box containing all geo_point values for a field.
  4. Example:
  5. [source,js]
  6. --------------------------------------------------
  7. PUT /museums
  8. {
  9. "mappings": {
  10. "properties": {
  11. "location": {
  12. "type": "geo_point"
  13. }
  14. }
  15. }
  16. }
  17. POST /museums/_bulk?refresh
  18. {"index":{"_id":1}}
  19. {"location": "52.374081,4.912350", "name": "NEMO Science Museum"}
  20. {"index":{"_id":2}}
  21. {"location": "52.369219,4.901618", "name": "Museum Het Rembrandthuis"}
  22. {"index":{"_id":3}}
  23. {"location": "52.371667,4.914722", "name": "Nederlands Scheepvaartmuseum"}
  24. {"index":{"_id":4}}
  25. {"location": "51.222900,4.405200", "name": "Letterenhuis"}
  26. {"index":{"_id":5}}
  27. {"location": "48.861111,2.336389", "name": "Musée du Louvre"}
  28. {"index":{"_id":6}}
  29. {"location": "48.860000,2.327000", "name": "Musée d'Orsay"}
  30. POST /museums/_search?size=0
  31. {
  32. "query" : {
  33. "match" : { "name" : "musée" }
  34. },
  35. "aggs" : {
  36. "viewport" : {
  37. "geo_bounds" : {
  38. "field" : "location", <1>
  39. "wrap_longitude" : true <2>
  40. }
  41. }
  42. }
  43. }
  44. --------------------------------------------------
  45. // CONSOLE
  46. <1> The `geo_bounds` aggregation specifies the field to use to obtain the bounds
  47. <2> `wrap_longitude` is an optional parameter which specifies whether the bounding box should be allowed to overlap the international date line. The default value is `true`
  48. The above aggregation demonstrates how one would compute the bounding box of the location field for all documents with a business type of shop
  49. The response for the above aggregation:
  50. [source,js]
  51. --------------------------------------------------
  52. {
  53. ...
  54. "aggregations": {
  55. "viewport": {
  56. "bounds": {
  57. "top_left": {
  58. "lat": 48.86111099738628,
  59. "lon": 2.3269999679178
  60. },
  61. "bottom_right": {
  62. "lat": 48.85999997612089,
  63. "lon": 2.3363889567553997
  64. }
  65. }
  66. }
  67. }
  68. }
  69. --------------------------------------------------
  70. // TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]