geotilegrid-aggregation.asciidoc 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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": "52.374081,4.912350", "name": "NEMO Science Museum"}
  44. {"index":{"_id":2}}
  45. {"location": "52.369219,4.901618", "name": "Museum Het Rembrandthuis"}
  46. {"index":{"_id":3}}
  47. {"location": "52.371667,4.914722", "name": "Nederlands Scheepvaartmuseum"}
  48. {"index":{"_id":4}}
  49. {"location": "51.222900,4.405200", "name": "Letterenhuis"}
  50. {"index":{"_id":5}}
  51. {"location": "48.861111,2.336389", "name": "Musée du Louvre"}
  52. {"index":{"_id":6}}
  53. {"location": "48.860000,2.327000", "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. ==== High-precision requests
  93. When requesting detailed buckets (typically for displaying a "zoomed in" map)
  94. a filter like <<query-dsl-geo-bounding-box-query,geo_bounding_box>> should be
  95. applied to narrow the subject area otherwise potentially millions of buckets
  96. will be created and returned.
  97. [source,console]
  98. --------------------------------------------------
  99. POST /museums/_search?size=0
  100. {
  101. "aggregations": {
  102. "zoomed-in": {
  103. "filter": {
  104. "geo_bounding_box": {
  105. "location": {
  106. "top_left": "52.4, 4.9",
  107. "bottom_right": "52.3, 5.0"
  108. }
  109. }
  110. },
  111. "aggregations": {
  112. "zoom1": {
  113. "geotile_grid": {
  114. "field": "location",
  115. "precision": 22
  116. }
  117. }
  118. }
  119. }
  120. }
  121. }
  122. --------------------------------------------------
  123. // TEST[continued]
  124. [source,console-result]
  125. --------------------------------------------------
  126. {
  127. ...
  128. "aggregations": {
  129. "zoomed-in": {
  130. "doc_count": 3,
  131. "zoom1": {
  132. "buckets": [
  133. {
  134. "key": "22/2154412/1378379",
  135. "doc_count": 1
  136. },
  137. {
  138. "key": "22/2154385/1378332",
  139. "doc_count": 1
  140. },
  141. {
  142. "key": "22/2154259/1378425",
  143. "doc_count": 1
  144. }
  145. ]
  146. }
  147. }
  148. }
  149. }
  150. --------------------------------------------------
  151. // TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]
  152. ==== Requests with additional bounding box filtering
  153. The `geotile_grid` aggregation supports an optional `bounds` parameter
  154. that restricts the cells considered to those that intersects the
  155. bounds provided. The `bounds` parameter accepts the bounding box in
  156. all the same <<query-dsl-geo-bounding-box-query-accepted-formats,accepted formats>> of the
  157. bounds specified in the Geo Bounding Box Query. This bounding box can be used with or
  158. without an additional `geo_bounding_box` query for filtering the points prior to aggregating.
  159. It is an independent bounding box that can intersect with, be equal to, or be disjoint
  160. to any additional `geo_bounding_box` queries defined in the context of the aggregation.
  161. [source,console,id=geotilegrid-aggregation-with-bounds]
  162. --------------------------------------------------
  163. POST /museums/_search?size=0
  164. {
  165. "aggregations": {
  166. "tiles-in-bounds": {
  167. "geotile_grid": {
  168. "field": "location",
  169. "precision": 22,
  170. "bounds": {
  171. "top_left": "52.4, 4.9",
  172. "bottom_right": "52.3, 5.0"
  173. }
  174. }
  175. }
  176. }
  177. }
  178. --------------------------------------------------
  179. // TEST[continued]
  180. [source,console-result]
  181. --------------------------------------------------
  182. {
  183. ...
  184. "aggregations": {
  185. "tiles-in-bounds": {
  186. "buckets": [
  187. {
  188. "key": "22/2154412/1378379",
  189. "doc_count": 1
  190. },
  191. {
  192. "key": "22/2154385/1378332",
  193. "doc_count": 1
  194. },
  195. {
  196. "key": "22/2154259/1378425",
  197. "doc_count": 1
  198. }
  199. ]
  200. }
  201. }
  202. }
  203. --------------------------------------------------
  204. // TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]
  205. [discrete]
  206. [role="xpack"]
  207. ==== Aggregating `geo_shape` fields
  208. Aggregating on <<geo-shape>> fields works just as it does for points, except that a single
  209. shape can be counted for in multiple tiles. A shape will contribute to the count of matching values
  210. if any part of its shape intersects with that tile. Below is an image that demonstrates this:
  211. image:images/spatial/geoshape_grid.png[]
  212. ==== Options
  213. [horizontal]
  214. field:: Mandatory. The name of the field indexed with GeoPoints.
  215. precision:: Optional. The integer zoom of the key used to define
  216. cells/buckets in the results. Defaults to 7.
  217. Values outside of [0,29] will be rejected.
  218. bounds: Optional. The bounding box to filter the points in the bucket.
  219. size:: Optional. The maximum number of geohash buckets to return
  220. (defaults to 10,000). When results are trimmed, buckets are
  221. prioritised based on the volumes of documents they contain.
  222. shard_size:: Optional. To allow for more accurate counting of the top cells
  223. returned in the final result the aggregation defaults to
  224. returning `max(10,(size x number-of-shards))` buckets from each
  225. shard. If this heuristic is undesirable, the number considered
  226. from each shard can be over-ridden using this parameter.