search-vector-tile-api.asciidoc 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  1. [[search-vector-tile-api]]
  2. === Vector tile search API
  3. ++++
  4. <titleabbrev>Vector tile search</titleabbrev>
  5. ++++
  6. Searches a vector tile for geospatial values. Returns results as a binary
  7. https://docs.mapbox.com/vector-tiles/specification[Mapbox vector tile].
  8. ////
  9. [source,console]
  10. ----
  11. PUT my-index
  12. {
  13. "mappings": {
  14. "properties": {
  15. "my-geo-field": {
  16. "type": "geo_point"
  17. }
  18. }
  19. }
  20. }
  21. PUT my-index/_doc/0?refresh
  22. {
  23. "my-geo-field": "POINT (-122.0863176 37.3864953)"
  24. }
  25. ----
  26. ////
  27. [source,console]
  28. ----
  29. GET my-index/_mvt/my-geo-field/15/5271/12710
  30. ----
  31. // TEST[continued]
  32. [[search-vector-tile-api-request]]
  33. ==== {api-request-title}
  34. `GET <target>/_mvt/<field>/<zoom>/<x>/<y>`
  35. `POST <target>/_mvt/<field>/<zoom>/<x>/<y>`
  36. [[search-vector-tile-api-prereqs]]
  37. ==== {api-prereq-title}
  38. * Before using this API, you should be familiar with the
  39. https://github.com/mapbox/vector-tile-spec[Mapbox vector tile specification].
  40. * If the {es} {security-features} are enabled, you must have the `read`
  41. <<privileges-list-indices,index privilege>> for the target data stream, index,
  42. or alias. For cross-cluster search, see <<remote-clusters-security>>.
  43. [[search-vector-tile-api-path-params]]
  44. ==== {api-path-parms-title}
  45. `<target>`::
  46. (Required, string) Comma-separated list of data streams, indices, or aliases to
  47. search. Supports wildcards (`*`). To search all data streams and indices, omit
  48. this parameter or use `*` or `_all`.
  49. +
  50. To search a remote cluster, use the `<cluster>:<target>` syntax. See
  51. <<modules-cross-cluster-search>>.
  52. `<field>`::
  53. (Required, string) Field containing geospatial values to return. Must be a
  54. <<geo-point,`geo_point`>> or <<geo-shape,`geo_shape`>> field. The field must
  55. have <<doc-values,doc values>> enabled. Cannot be a nested field.
  56. +
  57. NOTE: Vector tiles do not natively support geometry collections. For
  58. `geometrycollection` values in a `geo_shape` field, the API returns a `hits`
  59. layer feature for each element of the collection. This behavior may change may
  60. change in a future release.
  61. `<zoom>`::
  62. (Required, integer) Zoom level for the vector tile to search. Accepts `0`-`29`.
  63. `<x>`::
  64. (Required, integer) X coordinate for the vector tile to search.
  65. `<y>`::
  66. (Required, integer) Y coordinate for the vector tile to search.
  67. [[search-vector-tile-api-desc]]
  68. ==== {api-description-title}
  69. Internally, {es} translates a vector tile search API request into a
  70. <<search-search,search>> containing:
  71. * A <<query-dsl-geo-bounding-box-query,`geo_bounding_box`>> query on the
  72. `<field>`. The query uses the `<zoom>/<x>/<y>` tile as a bounding box.
  73. * A <<search-aggregations-bucket-geotilegrid-aggregation,`geotile_grid`>> or
  74. <<search-aggregations-bucket-geohexgrid-aggregation,`geohex_grid`>> aggregation
  75. on the `<field>`. The `grid_agg` parameter determines the aggregation type. The
  76. aggregation uses the `<zoom>/<x>/<y>` tile as a bounding box.
  77. * Optionally, a
  78. <<search-aggregations-metrics-geobounds-aggregation,`geo_bounds`>> aggregation
  79. on the `<field>`. The search only includes this aggregation if the
  80. `exact_bounds` parameter is `true`.
  81. * If the optional parameter `with_labels` is true, the internal search will include
  82. a dynamic runtime field that calls the `getLabelPosition` function of the geometry doc value.
  83. This enables the generation of new point features containing suggested geometry labels,
  84. so that, for example, multi-polygons will have only one label.
  85. For example, {es} may translate a vector tile search API request with a
  86. `grid_agg` argument of `geotile` and an `exact_bounds` argument of `true`
  87. into the following search:
  88. [source,console]
  89. ----
  90. GET my-index/_search
  91. {
  92. "size": 10000,
  93. "query": {
  94. "geo_bounding_box": {
  95. "my-geo-field": {
  96. "top_left": {
  97. "lat": -40.979898069620134,
  98. "lon": -45
  99. },
  100. "bottom_right": {
  101. "lat": -66.51326044311186,
  102. "lon": 0
  103. }
  104. }
  105. }
  106. },
  107. "aggregations": {
  108. "grid": {
  109. "geotile_grid": {
  110. "field": "my-geo-field",
  111. "precision": 11,
  112. "size": 65536,
  113. "bounds": {
  114. "top_left": {
  115. "lat": -40.979898069620134,
  116. "lon": -45
  117. },
  118. "bottom_right": {
  119. "lat": -66.51326044311186,
  120. "lon": 0
  121. }
  122. }
  123. }
  124. },
  125. "bounds": {
  126. "geo_bounds": {
  127. "field": "my-geo-field",
  128. "wrap_longitude": false
  129. }
  130. }
  131. }
  132. }
  133. ----
  134. // TEST[continued]
  135. The API returns results as a binary
  136. https://github.com/mapbox/vector-tile-spec[Mapbox vector tile]. Mapbox vector
  137. tiles are encoded as https://github.com/protocolbuffers/protobuf[Google
  138. Protobufs (PBF)]. By default, the tile contains three layers:
  139. * A `hits` layer containing a feature for each `<field>` value matching the
  140. `geo_bounding_box` query.
  141. * An `aggs` layer containing a feature for each cell of the `geotile_grid` or
  142. `geohex_grid`. The layer only contains features for cells with matching data.
  143. * A `meta` layer containing:
  144. ** A feature containing a bounding box. By default, this is the bounding box of
  145. the tile.
  146. ** Value ranges for any sub-aggregations on the `geotile_grid` or `geohex_grid`.
  147. ** Metadata for the search.
  148. The API only returns features that can display at its zoom level. For example,
  149. if a polygon feature has no area at its zoom level, the API omits it.
  150. The API returns errors as UTF-8 encoded JSON.
  151. [role="child_attributes"]
  152. [[search-vector-tile-api-query-params]]
  153. ==== {api-query-parms-title}
  154. IMPORTANT: You can specify several options for this API as either a query
  155. parameter or request body parameter. If you specify both parameters, the query
  156. parameter takes precedence.
  157. // tag::exact-bounds[]
  158. `exact_bounds`::
  159. (Optional, Boolean)
  160. If `false`, the `meta` layer's feature is the bounding box of the tile. Defaults
  161. to `false`.
  162. +
  163. If `true`, the `meta` layer's feature is a bounding box resulting from a
  164. <<search-aggregations-metrics-geobounds-aggregation,`geo_bounds`>> aggregation.
  165. The aggregation runs on `<field>` values that intersect the `<zoom>/<x>/<y>`
  166. tile with `wrap_longitude` set to `false`. The resulting bounding box may be
  167. larger than the vector tile.
  168. // end::exact-bounds[]
  169. // tag::extent-param[]
  170. `extent`::
  171. (Optional, integer) Size, in pixels, of a side of the tile. Vector tiles are
  172. square with equal sides. Defaults to `4096`.
  173. // end::extent-param[]
  174. // tag::buffer-param[]
  175. `buffer`::
  176. (Optional, integer) Size, in pixels, of a clipping buffer outside the tile.
  177. This allows renderers to avoid outline artifacts from geometries that extend past the extent of the tile.
  178. Defaults to `5`.
  179. // end::buffer-param[]
  180. // tag::grid-agg[]
  181. `grid_agg`::
  182. (Optional, string) Aggregation used to create a grid for the `<field>`.
  183. +
  184. .Valid values for `grid_agg`
  185. [%collapsible%open]
  186. ====
  187. `geotile` (Default)::
  188. <<search-aggregations-bucket-geotilegrid-aggregation,`geotile_grid`>> aggregation.
  189. `geohex`::
  190. <<search-aggregations-bucket-geohexgrid-aggregation,`geohex_grid`>> aggregation.
  191. ====
  192. // end::grid-agg[]
  193. // tag::grid-precision[]
  194. `grid_precision`::
  195. (Optional, integer) Precision level for cells in the `grid_agg`. Accepts
  196. `0`-`8`. Defaults to `8`. If `0`, results don't include the `aggs` layer.
  197. +
  198. .Grid precision for `geotile`
  199. [%collapsible%open]
  200. ====
  201. For a `grid_agg` of `geotile`, you can use cells in the `aggs` layer as tiles
  202. for lower zoom levels. `grid_precision` represents the additional zoom levels
  203. available through these cells. The final precision is computed by as
  204. follows:
  205. `<zoom> + grid_precision`
  206. For example, if `<zoom>` is `7` and `grid_precision` is `8`, then the
  207. `geotile_grid` aggregation will use a precision of `15`. The maximum final
  208. precision is `29`.
  209. The `grid_precision` also determines the number of cells for the grid as
  210. follows:
  211. `(2^grid_precision) x (2^grid_precision)`
  212. For example, a value of `8` divides the tile into a grid of 256 x 256 cells. The
  213. `aggs` layer only contains features for cells with matching data.
  214. ====
  215. +
  216. .Grid precision for `geohex`
  217. [%collapsible%open]
  218. ====
  219. For a `grid_agg` of `geohex`, {es} uses `<zoom>` and `grid_precision` to
  220. calculate a final precision as follows:
  221. `<zoom> + grid_precision`
  222. This precision determines the https://h3geo.org/docs/core-library/restable[H3
  223. resolution of the hexagonal cells] produced by the `geohex` aggregation. The
  224. following table maps the H3 resolution for each precision.
  225. For example, if `<zoom>` is `3` and `grid_precision` is `3`, the precision is
  226. `6`. At a precision of `6`, hexagonal cells have an H3 resolution of `2`. If
  227. `<zoom>` is `3` and `grid_precision` is `4`, the precision is `7`. At a
  228. precision of `7`, hexagonal cells have an H3 resolution of `3`.
  229. [cols="<,<,<,<,<",options="header",]
  230. |====
  231. |Precision | Unique tile bins| H3 resolution| Unique hex bins | Ratio
  232. |1 |4 |0 |122 |30.5
  233. |2 |16 |0 |122 |7.625
  234. |3 |64 |1 |842 |13.15625
  235. |4 |256 |1 |842 |3.2890625
  236. |5 |1024 |2 |5882 |5.744140625
  237. |6 |4096 |2 |5882 |1.436035156
  238. |7 |16384 |3 |41162 |2.512329102
  239. |8 |65536 |3 |41162 |0.6280822754
  240. |9 |262144 |4 |288122 |1.099098206
  241. |10 |1048576 |4 |288122 |0.2747745514
  242. |11 |4194304 |5 |2016842 |0.4808526039
  243. |12 |16777216 |6 |14117882 |0.8414913416
  244. |13 |67108864 |6 |14117882 |0.2103728354
  245. |14 |268435456 |7 |98825162 |0.3681524172
  246. |15 |1073741824 |8 |691776122 |0.644266719
  247. |16 |4294967296 |8 |691776122 |0.1610666797
  248. |17 |17179869184 |9 |4842432842 |0.2818666889
  249. |18 |68719476736 |10 |33897029882 |0.4932667053
  250. |19 |274877906944 |11 |237279209162 |0.8632167343
  251. |20 |1099511627776 |11 |237279209162 |0.2158041836
  252. |21 |4398046511104 |12 |1660954464122 |0.3776573213
  253. |22 |17592186044416 |13 |11626681248842 |0.6609003122
  254. |23 |70368744177664 |13 |11626681248842 |0.165225078
  255. |24 |281474976710656 |14 |81386768741882 |0.2891438866
  256. |25 |1125899906842620 |15 |569707381193162 |0.5060018015
  257. |26 |4503599627370500 |15 |569707381193162 |0.1265004504
  258. |27 |18014398509482000 |15 |569707381193162 |0.03162511259
  259. |28 |72057594037927900 |15 |569707381193162 |0.007906278149
  260. |29 |288230376151712000 |15 |569707381193162 |0.001976569537
  261. |====
  262. Hexagonal cells don't align perfectly on a vector tile. Some cells may intersect
  263. more than one vector tile. To compute the H3 resolution for each precision, {es}
  264. compares the average density of hexagonal bins at each resolution with the
  265. average density of tile bins at each zoom level. {es} uses the H3 resolution
  266. that is closest to the corresponding `geotile` density.
  267. ====
  268. // end::grid-precision[]
  269. // tag::grid-type[]
  270. `grid_type`::
  271. (Optional, string) Determines the geometry type for features in the `aggs`
  272. layer. In the `aggs` layer, each feature represents a cell in the grid.
  273. +
  274. .Valid values for `grid_type`
  275. [%collapsible%open]
  276. ====
  277. `grid` (Default)::
  278. Each feature is a `Polygon` of the cell's geometry. For a `grid_agg` of
  279. `geotile`, the feature is the cell's bounding box. For a `grid_agg` of
  280. `geohex`, the feature is the hexagonal cell's boundaries.
  281. `point`::
  282. Each feature is a `Point` that's the centroid of the cell.
  283. `centroid`::
  284. Each feature is a `Point` that's the centroid of the data within the cell. For
  285. complex geometries, the actual centroid may be outside the cell. In these cases,
  286. the feature is set to the closest point to the centroid inside the cell.
  287. ====
  288. // end::grid-type[]
  289. // tag::size[]
  290. `size`::
  291. (Optional, integer) Maximum number of features to return in the `hits` layer.
  292. Accepts `0`-`10000`. Defaults to `10000`. If `0`, results don't include the
  293. `hits` layer.
  294. // end::size[]
  295. // tag::track_total_hits[]
  296. `track_total_hits`::
  297. (Optional, integer or Boolean)
  298. Number of hits matching the query to count accurately. Defaults to `10000`.
  299. +
  300. If `true`, the exact number of hits is returned at the cost of some performance.
  301. If `false`, the response does not include the total number of hits matching the query.
  302. // end::track_total_hits[]
  303. // tag::with_labels[]
  304. `with_labels`::
  305. (Optional, Boolean)
  306. If true, the hits and aggs layers will contain additional point features representing
  307. suggested label positions for the original features.
  308. * `Point` and `MultiPoint` features will have one of the points selected.
  309. * `Polygon` and `MultiPolygon` features will have a single point generated,
  310. either the centroid, if it is within the polygon, or another point within the
  311. polygon selected from the <<geoshape-indexing-approach,sorted triangle-tree>>.
  312. * `LineString` features will likewise provide a roughly central point selected
  313. from the <<geoshape-indexing-approach,triangle-tree>>.
  314. * The aggregation results will provide one central point for each aggregation bucket.
  315. +
  316. All attributes from the original features will also be copied to the new label features.
  317. In addition, the new features will be distinguishable using the tag `_mvt_label_position`.
  318. // end::with_labels[]
  319. [role="child_attributes"]
  320. [[search-vector-tile-api-request-body]]
  321. ==== {api-request-body-title}
  322. `aggs`::
  323. (Optional, <<search-aggregations,aggregation object>>)
  324. <<run-sub-aggs,Sub-aggregations>> for the `grid_agg`. Supports the following
  325. aggregation types:
  326. +
  327. * <<search-aggregations-metrics-avg-aggregation,`avg`>>
  328. * <<search-aggregations-metrics-boxplot-aggregation,`boxplot`>>
  329. * <<search-aggregations-metrics-cardinality-aggregation,`cardinality`>>
  330. * <<search-aggregations-metrics-extendedstats-aggregation,`extended stats`>>
  331. * <<search-aggregations-metrics-max-aggregation,`max`>>
  332. * <<search-aggregations-metrics-median-absolute-deviation-aggregation,`median absolute deviation`>>
  333. * <<search-aggregations-metrics-min-aggregation,`min`>>
  334. * <<search-aggregations-metrics-percentile-aggregation,`percentile`>>
  335. * <<search-aggregations-metrics-percentile-rank-aggregation,`percentile-rank`>>
  336. * <<search-aggregations-metrics-stats-aggregation,`stats`>>
  337. * <<search-aggregations-metrics-sum-aggregation,`sum`>>
  338. * <<search-aggregations-metrics-valuecount-aggregation,`value count`>>
  339. +
  340. The aggregation names can't start with `_mvt_`. The `_mvt_` prefix is reserved
  341. for internal aggregations.
  342. include::search-vector-tile-api.asciidoc[tag=exact-bounds]
  343. include::search-vector-tile-api.asciidoc[tag=extent-param]
  344. include::search-vector-tile-api.asciidoc[tag=buffer-param]
  345. `fields`::
  346. (Optional, array of strings and objects) Fields to return in the `hits` layer.
  347. Supports wildcards (`*`).
  348. +
  349. This parameter does not support fields with <<array,array values>>. Fields with
  350. array values may return inconsistent results.
  351. +
  352. You can specify fields in the array as a string or object.
  353. +
  354. .Properties of `fields` objects
  355. [%collapsible%open]
  356. ====
  357. include::search.asciidoc[tag=fields-param-props]
  358. ====
  359. include::search-vector-tile-api.asciidoc[tag=grid-agg]
  360. include::search-vector-tile-api.asciidoc[tag=grid-precision]
  361. include::search-vector-tile-api.asciidoc[tag=grid-type]
  362. `query`::
  363. (Optional, object) <<query-dsl,Query DSL>> used to filter documents for the
  364. search.
  365. include::{es-repo-dir}/search/search.asciidoc[tag=runtime-mappings-def]
  366. include::search-vector-tile-api.asciidoc[tag=size]
  367. `sort`::
  368. (Optional, array of <<sort-search-results,sort objects>>) Sorts features in the
  369. `hits` layer.
  370. +
  371. By default, the API calculates a bounding box for each feature. It sorts
  372. features based on this box's diagonal length, from longest to shortest.
  373. include::search-vector-tile-api.asciidoc[tag=track_total_hits]
  374. include::search-vector-tile-api.asciidoc[tag=with_labels]
  375. [role="child_attributes"]
  376. [[search-vector-tile-api-response]]
  377. ==== Response
  378. Returned vector tiles contain the following data:
  379. `hits`::
  380. (object) Layer containing results for the `geo_bounding_box` query.
  381. +
  382. .Properties of `hits`
  383. [%collapsible%open]
  384. ====
  385. // tag::extent[]
  386. `extent`::
  387. (integer) Size, in pixels, of a side of the tile. Vector tiles are square with
  388. equal sides.
  389. // end::extent[]
  390. // tag::version[]
  391. `version`::
  392. (integer) Major version number of the
  393. https://github.com/mapbox/vector-tile-spec[Mapbox vector tile specification].
  394. // end::version[]
  395. `features`::
  396. (array of objects) Array of features. Contains a feature for each `<field>`
  397. value that matches the `geo_bounding_box` query.
  398. +
  399. .Properties of `features` objects
  400. [%collapsible%open]
  401. =====
  402. // tag::geometry[]
  403. `geometry`::
  404. (object) Geometry for the feature.
  405. +
  406. .Properties of `geometry`
  407. [%collapsible%open]
  408. ======
  409. `type`::
  410. (string) Geometry type for the feature. Valid values are:
  411. * `UNKNOWN`
  412. * `POINT`
  413. * `LINESTRING`
  414. * `POLYGON`
  415. `coordinates`::
  416. (array of integers or array of arrays) Tile coordinates for the feature.
  417. ======
  418. // end::geometry[]
  419. `properties`::
  420. (object) Properties for the feature.
  421. +
  422. .Properties of `properties`
  423. [%collapsible%open]
  424. ======
  425. `_id`::
  426. (string) Document `_id` for the feature's document.
  427. `_index`::
  428. (string) Name of the index for the feature's document.
  429. `<field>`::
  430. Field value. Only returned for fields in the `fields` parameter.
  431. ======
  432. // tag::feature-type[]
  433. `type`::
  434. (integer) Identifier for the feature's geometry type. Values are:
  435. +
  436. * `1` (`POINT`)
  437. * `2` (`LINESTRING`)
  438. * `3` (`POLYGON`)
  439. // end::feature-type[]
  440. =====
  441. ====
  442. `aggs`::
  443. (object) Layer containing results for the `grid_agg` aggregation and its
  444. sub-aggregations.
  445. +
  446. .Properties of `aggs`
  447. [%collapsible%open]
  448. ====
  449. include::search-vector-tile-api.asciidoc[tag=extent]
  450. include::search-vector-tile-api.asciidoc[tag=version]
  451. `features`::
  452. (array of objects) Array of features. Contains a feature for each cell of the grid.
  453. +
  454. .Properties of `features` objects
  455. [%collapsible%open]
  456. =====
  457. include::search-vector-tile-api.asciidoc[tag=geometry]
  458. `properties`::
  459. (object) Properties for the feature.
  460. +
  461. .Properties of `properties`
  462. [%collapsible%open]
  463. ======
  464. `_count`::
  465. (long) Count of the cell's documents.
  466. `_key`::
  467. (string) Bucket key of the cell in the format `<zoom>/<x>/<y>`.
  468. `<sub-aggregation>.value`::
  469. Sub-aggregation results for the cell. Only returned for sub-aggregations in the
  470. `aggs` parameter.
  471. ======
  472. include::search-vector-tile-api.asciidoc[tag=feature-type]
  473. =====
  474. ====
  475. `meta`::
  476. (object) Layer containing metadata for the request.
  477. +
  478. .Properties of `meta`
  479. [%collapsible%open]
  480. ====
  481. include::search-vector-tile-api.asciidoc[tag=extent]
  482. include::search-vector-tile-api.asciidoc[tag=version]
  483. `features`::
  484. (array of objects) Contains a feature for a bounding box.
  485. +
  486. .Properties of `features` objects
  487. [%collapsible%open]
  488. =====
  489. include::search-vector-tile-api.asciidoc[tag=geometry]
  490. `properties`::
  491. (object) Properties for the feature.
  492. +
  493. .Properties of `properties`
  494. [%collapsible%open]
  495. ======
  496. `_shards.failed`::
  497. (integer) Number of shards that failed to execute the search. See the search
  498. API's <<search-api-shards,`shards`>> response property.
  499. `_shards.skipped`::
  500. (integer) Number of shards that skipped the search. See the search
  501. API's <<search-api-shards,`shards`>> response property.
  502. `_shards.successful`::
  503. (integer) Number of shards that executed the search successfully. See the
  504. search API's <<search-api-shards,`shards`>> response property.
  505. `_shards.total`::
  506. (integer) Total number of shards that required querying, including unallocated
  507. shards. See the search API's <<search-api-shards,`shards`>> response property.
  508. `aggregations._count.avg`::
  509. (float) Average `_count` value for features in the `aggs` layer.
  510. `aggregations._count.count`::
  511. (integer) Number of unique `_count` values for features in the `aggs` layer.
  512. `aggregations._count.max`::
  513. (float) Largest `_count` value for features in the `aggs` layer.
  514. `aggregations._count.min`::
  515. (float) Smallest `_count` value for features in the `aggs` layer.
  516. `aggregations._count.sum`::
  517. (float) Sum of `_count` values for features in the `aggs` layer.
  518. `aggregations.<sub-aggregation>.avg`::
  519. (float) Average value for the sub-aggregation's results.
  520. `aggregations.<agg_name>.count`::
  521. (integer) Number of unique values from the sub-aggregation's results.
  522. `aggregations.<agg_name>.max`::
  523. (float) Largest value from the sub-aggregation's results.
  524. `aggregations.<agg_name>.min`::
  525. (float) Smallest value from the sub-aggregation's results.
  526. `aggregations.<agg_name>.sum`::
  527. (float) Sum of values for the sub-aggregation's results.
  528. `hits.max_score`::
  529. (float) Highest document `_score` for the search's hits.
  530. `hits.total.relation`::
  531. (string) Indicates whether `hits.total.value` is accurate or a lower bound.
  532. Possible values are:
  533. `eq`::: Accurate
  534. `gte`::: Lower bound
  535. `hits.total.value`::
  536. (integer) Total number of hits for the search.
  537. `timed_out`::
  538. (Boolean) If `true`, the search timed out before completion. Results may be
  539. partial or empty.
  540. `took`::
  541. (integer) Milliseconds it took {es} to run the search. See the search API's
  542. <<search-api-took,`took`>> response property.
  543. ======
  544. include::search-vector-tile-api.asciidoc[tag=feature-type]
  545. =====
  546. ====
  547. [[search-vector-tile-api-api-example]]
  548. ==== {api-examples-title}
  549. The following requests create the `museum` index and add several geospatial
  550. `location` values.
  551. [source,console]
  552. ----
  553. PUT museums
  554. {
  555. "mappings": {
  556. "properties": {
  557. "location": {
  558. "type": "geo_point"
  559. },
  560. "name": {
  561. "type": "keyword"
  562. },
  563. "price": {
  564. "type": "long"
  565. },
  566. "included": {
  567. "type": "boolean"
  568. }
  569. }
  570. }
  571. }
  572. POST museums/_bulk?refresh
  573. { "index": { "_id": "1" } }
  574. { "location": "POINT (4.912350 52.374081)", "name": "NEMO Science Museum", "price": 1750, "included": true }
  575. { "index": { "_id": "2" } }
  576. { "location": "POINT (4.901618 52.369219)", "name": "Museum Het Rembrandthuis", "price": 1500, "included": false }
  577. { "index": { "_id": "3" } }
  578. { "location": "POINT (4.914722 52.371667)", "name": "Nederlands Scheepvaartmuseum", "price":1650, "included": true }
  579. { "index": { "_id": "4" } }
  580. { "location": "POINT (4.914722 52.371667)", "name": "Amsterdam Centre for Architecture", "price":0, "included": true }
  581. ----
  582. The following request searches the index for `location` values that intersect
  583. the `13/4207/2692` vector tile.
  584. [source,console]
  585. ----
  586. GET museums/_mvt/location/13/4207/2692
  587. {
  588. "grid_agg": "geotile",
  589. "grid_precision": 2,
  590. "fields": [
  591. "name",
  592. "price"
  593. ],
  594. "query": {
  595. "term": {
  596. "included": true
  597. }
  598. },
  599. "aggs": {
  600. "min_price": {
  601. "min": {
  602. "field": "price"
  603. }
  604. },
  605. "max_price": {
  606. "max": {
  607. "field": "price"
  608. }
  609. },
  610. "avg_price": {
  611. "avg": {
  612. "field": "price"
  613. }
  614. }
  615. }
  616. }
  617. ----
  618. // TEST[continued]
  619. The API returns results as a binary vector tile. When decoded into JSON, the
  620. tile contains the following data:
  621. [source,js]
  622. ----
  623. {
  624. "hits": {
  625. "extent": 4096,
  626. "version": 2,
  627. "features": [
  628. {
  629. "geometry": {
  630. "type": "Point",
  631. "coordinates": [
  632. 3208,
  633. 3864
  634. ]
  635. },
  636. "properties": {
  637. "_id": "1",
  638. "_index": "museums",
  639. "name": "NEMO Science Museum",
  640. "price": 1750
  641. },
  642. "type": 1
  643. },
  644. {
  645. "geometry": {
  646. "type": "Point",
  647. "coordinates": [
  648. 3429,
  649. 3496
  650. ]
  651. },
  652. "properties": {
  653. "_id": "3",
  654. "_index": "museums",
  655. "name": "Nederlands Scheepvaartmuseum",
  656. "price": 1650
  657. },
  658. "type": 1
  659. },
  660. {
  661. "geometry": {
  662. "type": "Point",
  663. "coordinates": [
  664. 3429,
  665. 3496
  666. ]
  667. },
  668. "properties": {
  669. "_id": "4",
  670. "_index": "museums",
  671. "name": "Amsterdam Centre for Architecture",
  672. "price": 0
  673. },
  674. "type": 1
  675. }
  676. ]
  677. },
  678. "aggs": {
  679. "extent": 4096,
  680. "version": 2,
  681. "features": [
  682. {
  683. "geometry": {
  684. "type": "Polygon",
  685. "coordinates": [
  686. [
  687. [
  688. 3072,
  689. 3072
  690. ],
  691. [
  692. 4096,
  693. 3072
  694. ],
  695. [
  696. 4096,
  697. 4096
  698. ],
  699. [
  700. 3072,
  701. 4096
  702. ],
  703. [
  704. 3072,
  705. 3072
  706. ]
  707. ]
  708. ]
  709. },
  710. "properties": {
  711. "_count": 3,
  712. "max_price.value": 1750.0,
  713. "min_price.value": 0.0,
  714. "avg_price.value": 1133.3333333333333
  715. },
  716. "type": 3
  717. }
  718. ]
  719. },
  720. "meta": {
  721. "extent": 4096,
  722. "version": 2,
  723. "features": [
  724. {
  725. "geometry": {
  726. "type": "Polygon",
  727. "coordinates": [
  728. [
  729. [
  730. 0,
  731. 0
  732. ],
  733. [
  734. 4096,
  735. 0
  736. ],
  737. [
  738. 4096,
  739. 4096
  740. ],
  741. [
  742. 0,
  743. 4096
  744. ],
  745. [
  746. 0,
  747. 0
  748. ]
  749. ]
  750. ]
  751. },
  752. "properties": {
  753. "_shards.failed": 0,
  754. "_shards.skipped": 0,
  755. "_shards.successful": 1,
  756. "_shards.total": 1,
  757. "aggregations._count.avg": 3.0,
  758. "aggregations._count.count": 1,
  759. "aggregations._count.max": 3.0,
  760. "aggregations._count.min": 3.0,
  761. "aggregations._count.sum": 3.0,
  762. "aggregations.avg_price.avg": 1133.3333333333333,
  763. "aggregations.avg_price.count": 1,
  764. "aggregations.avg_price.max": 1133.3333333333333,
  765. "aggregations.avg_price.min": 1133.3333333333333,
  766. "aggregations.avg_price.sum": 1133.3333333333333,
  767. "aggregations.max_price.avg": 1750.0,
  768. "aggregations.max_price.count": 1,
  769. "aggregations.max_price.max": 1750.0,
  770. "aggregations.max_price.min": 1750.0,
  771. "aggregations.max_price.sum": 1750.0,
  772. "aggregations.min_price.avg": 0.0,
  773. "aggregations.min_price.count": 1,
  774. "aggregations.min_price.max": 0.0,
  775. "aggregations.min_price.min": 0.0,
  776. "aggregations.min_price.sum": 0.0,
  777. "hits.max_score": 0.0,
  778. "hits.total.relation": "eq",
  779. "hits.total.value": 3,
  780. "timed_out": false,
  781. "took": 2
  782. },
  783. "type": 3
  784. }
  785. ]
  786. }
  787. }
  788. ----
  789. // NOTCONSOLE