geobounds-aggregation.asciidoc 2.3 KB

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