cartesian-bounds-aggregation.asciidoc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. [[search-aggregations-metrics-cartesian-bounds-aggregation]]
  2. === Cartesian-bounds aggregation
  3. ++++
  4. <titleabbrev>Cartesian-bounds</titleabbrev>
  5. ++++
  6. A metric aggregation that computes the spatial bounding box containing all values for a <<point>> or <<shape>> field.
  7. Example:
  8. [source,console]
  9. --------------------------------------------------
  10. PUT /museums
  11. {
  12. "mappings": {
  13. "properties": {
  14. "location": {
  15. "type": "point"
  16. }
  17. }
  18. }
  19. }
  20. POST /museums/_bulk?refresh
  21. {"index":{"_id":1}}
  22. {"location": "POINT (491.2350 5237.4081)", "city": "Amsterdam", "name": "NEMO Science Museum"}
  23. {"index":{"_id":2}}
  24. {"location": "POINT (490.1618 5236.9219)", "city": "Amsterdam", "name": "Museum Het Rembrandthuis"}
  25. {"index":{"_id":3}}
  26. {"location": "POINT (491.4722 5237.1667)", "city": "Amsterdam", "name": "Nederlands Scheepvaartmuseum"}
  27. {"index":{"_id":4}}
  28. {"location": "POINT (440.5200 5122.2900)", "city": "Antwerp", "name": "Letterenhuis"}
  29. {"index":{"_id":5}}
  30. {"location": "POINT (233.6389 4886.1111)", "city": "Paris", "name": "Musée du Louvre"}
  31. {"index":{"_id":6}}
  32. {"location": "POINT (232.7000 4886.0000)", "city": "Paris", "name": "Musée d'Orsay"}
  33. POST /museums/_search?size=0
  34. {
  35. "query": {
  36. "match": { "name": "musée" }
  37. },
  38. "aggs": {
  39. "viewport": {
  40. "cartesian_bounds": {
  41. "field": "location" <1>
  42. }
  43. }
  44. }
  45. }
  46. --------------------------------------------------
  47. <1> The `cartesian_bounds` aggregation specifies the field to use to obtain the bounds, which must be a <<point>> or a <<shape>> type.
  48. [NOTE]
  49. Unlike the case with the <<geobounds-aggregation-geo-shape, `geo_bounds`>> aggregation,
  50. there is no option to set <<geo-bounds-wrap-longitude, `wrap_longitude`>>.
  51. This is because the cartesian space is euclidean and does not wrap back on itself.
  52. So the bounds will always have a minimum x value less than or equal to the maximum x value.
  53. The above aggregation demonstrates how one would compute the bounding box of the location field for all documents with a name matching "musée".
  54. The response for the above aggregation:
  55. [source,console-result]
  56. --------------------------------------------------
  57. {
  58. ...
  59. "aggregations": {
  60. "viewport": {
  61. "bounds": {
  62. "top_left": {
  63. "x": 232.6999969482422,
  64. "y": 4886.111328125
  65. },
  66. "bottom_right": {
  67. "x": 233.63890075683594,
  68. "y": 4886.0
  69. }
  70. }
  71. }
  72. }
  73. }
  74. --------------------------------------------------
  75. // TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]
  76. [discrete]
  77. [role="xpack"]
  78. [[cartesian-bounds-aggregation-shape]]
  79. ==== Cartesian Bounds Aggregation on `shape` fields
  80. The Cartesian Bounds Aggregation is also supported on `cartesian_shape` fields.
  81. Example:
  82. [source,console]
  83. --------------------------------------------------
  84. PUT /places
  85. {
  86. "mappings": {
  87. "properties": {
  88. "geometry": {
  89. "type": "shape"
  90. }
  91. }
  92. }
  93. }
  94. POST /places/_bulk?refresh
  95. {"index":{"_id":1}}
  96. {"name": "NEMO Science Museum", "geometry": "POINT(491.2350 5237.4081)" }
  97. {"index":{"_id":2}}
  98. {"name": "Sportpark De Weeren", "geometry": { "type": "Polygon", "coordinates": [ [ [ 496.5305328369141, 5239.347642069457 ], [ 496.6979026794433, 5239.1721758934835 ], [ 496.9425201416015, 5239.238958618537 ], [ 496.7944622039794, 5239.420969150824 ], [ 496.5305328369141, 5239.347642069457 ] ] ] } }
  99. POST /places/_search?size=0
  100. {
  101. "aggs": {
  102. "viewport": {
  103. "cartesian_bounds": {
  104. "field": "geometry"
  105. }
  106. }
  107. }
  108. }
  109. --------------------------------------------------
  110. // TEST
  111. [source,console-result]
  112. --------------------------------------------------
  113. {
  114. ...
  115. "aggregations": {
  116. "viewport": {
  117. "bounds": {
  118. "top_left": {
  119. "x": 491.2349853515625,
  120. "y": 5239.4208984375
  121. },
  122. "bottom_right": {
  123. "x": 496.9425048828125,
  124. "y": 5237.408203125
  125. }
  126. }
  127. }
  128. }
  129. }
  130. --------------------------------------------------
  131. // TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]