geotilegrid-aggregation.asciidoc 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. [[search-aggregations-bucket-geotilegrid-aggregation]]
  2. === Geotile grid aggregation
  3. ++++
  4. <titleabbrev>Geotile grid</titleabbrev>
  5. ++++
  6. A multi-bucket aggregation that groups <<geo-point,`geo_point`>> and
  7. <<geo-shape,`geo_shape`>> values into buckets that represent a grid.
  8. The resulting grid can be sparse and only
  9. contains cells that have matching data. Each cell corresponds to a
  10. {wikipedia}/Tiled_web_map[map tile] as used by many online map
  11. sites. Each cell is labeled using a "{zoom}/{x}/{y}" format, where zoom is equal
  12. to the user-specified precision.
  13. * High precision keys have a larger range for x and y, and represent tiles that
  14. cover only a small area.
  15. * Low precision keys have a smaller range for x and y, and represent tiles that
  16. each cover a large area.
  17. See https://wiki.openstreetmap.org/wiki/Zoom_levels[zoom level documentation]
  18. on how precision (zoom) correlates to size on the ground. Precision for this
  19. aggregation can be between 0 and 29, inclusive.
  20. WARNING: The highest-precision geotile of length 29 produces cells that cover
  21. less than a 10cm by 10cm of land and so high-precision requests can be very
  22. costly in terms of RAM and result sizes. Please see the example below on how
  23. to first filter the aggregation to a smaller geographic area before requesting
  24. high-levels of detail.
  25. You can only use `geotile_grid` to aggregate an explicitly mapped `geo_point` or
  26. `geo_shape` field. If the `geo_point` field contains an array, `geotile_grid`
  27. aggregates all the array values.
  28. ==== Simple low-precision request
  29. [source,console,id=geotilegrid-aggregation-example]
  30. --------------------------------------------------
  31. PUT /museums
  32. {
  33. "mappings": {
  34. "properties": {
  35. "location": {
  36. "type": "geo_point"
  37. }
  38. }
  39. }
  40. }
  41. POST /museums/_bulk?refresh
  42. {"index":{"_id":1}}
  43. {"location": "POINT (4.912350 52.374081)", "name": "NEMO Science Museum"}
  44. {"index":{"_id":2}}
  45. {"location": "POINT (4.901618 52.369219)", "name": "Museum Het Rembrandthuis"}
  46. {"index":{"_id":3}}
  47. {"location": "POINT (4.914722 52.371667)", "name": "Nederlands Scheepvaartmuseum"}
  48. {"index":{"_id":4}}
  49. {"location": "POINT (4.405200 51.222900)", "name": "Letterenhuis"}
  50. {"index":{"_id":5}}
  51. {"location": "POINT (2.336389 48.861111)", "name": "Musée du Louvre"}
  52. {"index":{"_id":6}}
  53. {"location": "POINT (2.327000 48.860000)", "name": "Musée d'Orsay"}
  54. POST /museums/_search?size=0
  55. {
  56. "aggregations": {
  57. "large-grid": {
  58. "geotile_grid": {
  59. "field": "location",
  60. "precision": 8
  61. }
  62. }
  63. }
  64. }
  65. --------------------------------------------------
  66. Response:
  67. [source,console-result]
  68. --------------------------------------------------
  69. {
  70. ...
  71. "aggregations": {
  72. "large-grid": {
  73. "buckets": [
  74. {
  75. "key": "8/131/84",
  76. "doc_count": 3
  77. },
  78. {
  79. "key": "8/129/88",
  80. "doc_count": 2
  81. },
  82. {
  83. "key": "8/131/85",
  84. "doc_count": 1
  85. }
  86. ]
  87. }
  88. }
  89. }
  90. --------------------------------------------------
  91. // TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]
  92. [[geotilegrid-high-precision]]
  93. ==== High-precision requests
  94. When requesting detailed buckets (typically for displaying a "zoomed in" map),
  95. a filter like <<query-dsl-geo-bounding-box-query,geo_bounding_box>> should be
  96. applied to narrow the subject area. Otherwise, potentially millions of buckets
  97. will be created and returned.
  98. [source,console,id=geotilegrid-high-precision-ex]
  99. --------------------------------------------------
  100. POST /museums/_search?size=0
  101. {
  102. "aggregations": {
  103. "zoomed-in": {
  104. "filter": {
  105. "geo_bounding_box": {
  106. "location": {
  107. "top_left": "POINT (4.9 52.4)",
  108. "bottom_right": "POINT (5.0 52.3)"
  109. }
  110. }
  111. },
  112. "aggregations": {
  113. "zoom1": {
  114. "geotile_grid": {
  115. "field": "location",
  116. "precision": 22
  117. }
  118. }
  119. }
  120. }
  121. }
  122. }
  123. --------------------------------------------------
  124. // TEST[continued]
  125. Response:
  126. [source,console-result]
  127. --------------------------------------------------
  128. {
  129. ...
  130. "aggregations": {
  131. "zoomed-in": {
  132. "doc_count": 3,
  133. "zoom1": {
  134. "buckets": [
  135. {
  136. "key": "22/2154412/1378379",
  137. "doc_count": 1
  138. },
  139. {
  140. "key": "22/2154385/1378332",
  141. "doc_count": 1
  142. },
  143. {
  144. "key": "22/2154259/1378425",
  145. "doc_count": 1
  146. }
  147. ]
  148. }
  149. }
  150. }
  151. }
  152. --------------------------------------------------
  153. // TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]
  154. [[geotilegrid-addtl-bounding-box-filtering]]
  155. ==== Requests with additional bounding box filtering
  156. The `geotile_grid` aggregation supports an optional `bounds` parameter
  157. that restricts the cells considered to those that intersect the
  158. provided bounds. The `bounds` parameter accepts the same
  159. <<query-dsl-geo-bounding-box-query-accepted-formats,bounding box formats>>
  160. as the geo-bounding box query. This bounding box can be used with or
  161. without an additional `geo_bounding_box` query for filtering the points prior to aggregating.
  162. It is an independent bounding box that can intersect with, be equal to, or be disjoint
  163. to any additional `geo_bounding_box` queries defined in the context of the aggregation.
  164. [source,console,id=geotilegrid-aggregation-with-bounds]
  165. --------------------------------------------------
  166. POST /museums/_search?size=0
  167. {
  168. "aggregations": {
  169. "tiles-in-bounds": {
  170. "geotile_grid": {
  171. "field": "location",
  172. "precision": 22,
  173. "bounds": {
  174. "top_left": "POINT (4.9 52.4)",
  175. "bottom_right": "POINT (5.0 52.3)"
  176. }
  177. }
  178. }
  179. }
  180. }
  181. --------------------------------------------------
  182. // TEST[continued]
  183. Response:
  184. [source,console-result]
  185. --------------------------------------------------
  186. {
  187. ...
  188. "aggregations": {
  189. "tiles-in-bounds": {
  190. "buckets": [
  191. {
  192. "key": "22/2154412/1378379",
  193. "doc_count": 1
  194. },
  195. {
  196. "key": "22/2154385/1378332",
  197. "doc_count": 1
  198. },
  199. {
  200. "key": "22/2154259/1378425",
  201. "doc_count": 1
  202. }
  203. ]
  204. }
  205. }
  206. }
  207. --------------------------------------------------
  208. // TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]
  209. [discrete]
  210. [role="xpack"]
  211. [[geotilegrid-aggregating-geo-shape]]
  212. ==== Aggregating `geo_shape` fields
  213. Aggregating on <<geo-shape>> fields works almost as it does for points, except that a single
  214. shape can be counted for in multiple tiles. A shape will contribute to the count of matching values
  215. if any part of its shape intersects with that tile. Below is an image that demonstrates this:
  216. image:images/spatial/geoshape_grid.png[]
  217. ==== Options
  218. [horizontal]
  219. field::
  220. (Required, string) Field containing indexed geo-point or geo-shape values.
  221. Must be explicitly mapped as a <<geo-point,`geo_point`>> or a <<geo-shape,`geo_shape`>> field.
  222. If the field contains an array, `geotile_grid` aggregates all array values.
  223. precision::
  224. (Optional, integer) Integer zoom of the key used to define cells/buckets in
  225. the results. Defaults to `7`. Values outside of [`0`,`29`] will be rejected.
  226. bounds::
  227. (Optional, object) Bounding box used to filter the geo-points or geo-shapes in each bucket.
  228. Accepts the same bounding box formats as the
  229. <<query-dsl-geo-bounding-box-query-accepted-formats,geo-bounding box query>>.
  230. size::
  231. (Optional, integer) Maximum number of buckets to return. Defaults to 10,000.
  232. When results are trimmed, buckets are prioritized based on the volume of
  233. documents they contain.
  234. shard_size::
  235. (Optional, integer) Number of buckets returned from each shard. Defaults to
  236. `max(10,(size x number-of-shards))` to allow for a more accurate count of the
  237. top cells in the final result. Since each shard could have a different top result order,
  238. using a larger number here reduces the risk of inaccurate counts, but incurs a performance cost.