geotilegrid-aggregation.asciidoc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. [[search-aggregations-bucket-geotilegrid-aggregation]]
  2. === GeoTile Grid Aggregation
  3. A multi-bucket aggregation that works on `geo_point` fields and groups points into
  4. buckets that represent cells in a grid. The resulting grid can be sparse and only
  5. contains cells that have matching data. Each cell corresponds to a
  6. https://en.wikipedia.org/wiki/Tiled_web_map[map tile] as used by many online map
  7. sites. Each cell is labeled using a "{zoom}/{x}/{y}" format, where zoom is equal
  8. to the user-specified precision.
  9. * High precision keys have a larger range for x and y, and represent tiles that
  10. cover only a small area.
  11. * Low precision keys have a smaller range for x and y, and represent tiles that
  12. each cover a large area.
  13. See https://wiki.openstreetmap.org/wiki/Zoom_levels[Zoom level documentation]
  14. on how precision (zoom) correlates to size on the ground. Precision for this
  15. aggregation can be between 0 and 29, inclusive.
  16. WARNING: The highest-precision geotile of length 29 produces cells that cover
  17. less than a 10cm by 10cm of land and so high-precision requests can be very
  18. costly in terms of RAM and result sizes. Please see the example below on how
  19. to first filter the aggregation to a smaller geographic area before requesting
  20. high-levels of detail.
  21. The specified field must be of type `geo_point` (which can only be set
  22. explicitly in the mappings) and it can also hold an array of `geo_point`
  23. fields, in which case all points will be taken into account during aggregation.
  24. ==== Simple low-precision request
  25. [source,js]
  26. --------------------------------------------------
  27. PUT /museums
  28. {
  29. "mappings": {
  30. "properties": {
  31. "location": {
  32. "type": "geo_point"
  33. }
  34. }
  35. }
  36. }
  37. POST /museums/_bulk?refresh
  38. {"index":{"_id":1}}
  39. {"location": "52.374081,4.912350", "name": "NEMO Science Museum"}
  40. {"index":{"_id":2}}
  41. {"location": "52.369219,4.901618", "name": "Museum Het Rembrandthuis"}
  42. {"index":{"_id":3}}
  43. {"location": "52.371667,4.914722", "name": "Nederlands Scheepvaartmuseum"}
  44. {"index":{"_id":4}}
  45. {"location": "51.222900,4.405200", "name": "Letterenhuis"}
  46. {"index":{"_id":5}}
  47. {"location": "48.861111,2.336389", "name": "Musée du Louvre"}
  48. {"index":{"_id":6}}
  49. {"location": "48.860000,2.327000", "name": "Musée d'Orsay"}
  50. POST /museums/_search?size=0
  51. {
  52. "aggregations" : {
  53. "large-grid" : {
  54. "geotile_grid" : {
  55. "field" : "location",
  56. "precision" : 8
  57. }
  58. }
  59. }
  60. }
  61. --------------------------------------------------
  62. // CONSOLE
  63. Response:
  64. [source,js]
  65. --------------------------------------------------
  66. {
  67. ...
  68. "aggregations": {
  69. "large-grid": {
  70. "buckets": [
  71. {
  72. "key" : "8/131/84",
  73. "doc_count" : 3
  74. },
  75. {
  76. "key" : "8/129/88",
  77. "doc_count" : 2
  78. },
  79. {
  80. "key" : "8/131/85",
  81. "doc_count" : 1
  82. }
  83. ]
  84. }
  85. }
  86. }
  87. --------------------------------------------------
  88. // TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]
  89. ==== High-precision requests
  90. When requesting detailed buckets (typically for displaying a "zoomed in" map)
  91. a filter like <<query-dsl-geo-bounding-box-query,geo_bounding_box>> should be
  92. applied to narrow the subject area otherwise potentially millions of buckets
  93. will be created and returned.
  94. [source,js]
  95. --------------------------------------------------
  96. POST /museums/_search?size=0
  97. {
  98. "aggregations" : {
  99. "zoomed-in" : {
  100. "filter" : {
  101. "geo_bounding_box" : {
  102. "location" : {
  103. "top_left" : "52.4, 4.9",
  104. "bottom_right" : "52.3, 5.0"
  105. }
  106. }
  107. },
  108. "aggregations":{
  109. "zoom1":{
  110. "geotile_grid" : {
  111. "field": "location",
  112. "precision": 22
  113. }
  114. }
  115. }
  116. }
  117. }
  118. }
  119. --------------------------------------------------
  120. // CONSOLE
  121. // TEST[continued]
  122. [source,js]
  123. --------------------------------------------------
  124. {
  125. ...
  126. "aggregations" : {
  127. "zoomed-in" : {
  128. "doc_count" : 3,
  129. "zoom1" : {
  130. "buckets" : [
  131. {
  132. "key" : "22/2154412/1378379",
  133. "doc_count" : 1
  134. },
  135. {
  136. "key" : "22/2154385/1378332",
  137. "doc_count" : 1
  138. },
  139. {
  140. "key" : "22/2154259/1378425",
  141. "doc_count" : 1
  142. }
  143. ]
  144. }
  145. }
  146. }
  147. }
  148. --------------------------------------------------
  149. // TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]
  150. ==== Options
  151. [horizontal]
  152. field:: Mandatory. The name of the field indexed with GeoPoints.
  153. precision:: Optional. The integer zoom of the key used to define
  154. cells/buckets in the results. Defaults to 7.
  155. Values outside of [0,29] will be rejected.
  156. size:: Optional. The maximum number of geohash buckets to return
  157. (defaults to 10,000). When results are trimmed, buckets are
  158. prioritised based on the volumes of documents they contain.
  159. shard_size:: Optional. To allow for more accurate counting of the top cells
  160. returned in the final result the aggregation defaults to
  161. returning `max(10,(size x number-of-shards))` buckets from each
  162. shard. If this heuristic is undesirable, the number considered
  163. from each shard can be over-ridden using this parameter.