Skip to content

Commit ee1c523

Browse files
Add vector tile examples
1 parent ed7f2ca commit ee1c523

File tree

1 file changed

+269
-0
lines changed

1 file changed

+269
-0
lines changed
Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
---
2+
mapped_pages:
3+
- https://www.elastic.co/guide/en/elasticsearch/reference/8.18/search-vector-tile-api.html#search-vector-tile-api-api-example
4+
applies_to:
5+
stack: all
6+
navigation_title: Vector tile search
7+
---
8+
9+
# Vector tile search examples
10+
11+
This page shows how to create an index with geospatial data and retrieve vector tile results using the [vector tile search API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-search-mvt-1).
12+
13+
14+
You can learn how to:
15+
- [Create an index with geospatial fields](#create-an-index-with-geospatial-fields)
16+
- [Query geospatial data using a vector tile](#query-a-vector-tile-for-geospatial-data)
17+
- [Understand the structure of the API response](#example-response)
18+
19+
## Create an index with geospatial fields
20+
21+
The following requests create the `museum` index and add several geospatial
22+
`location` values.
23+
24+
```console
25+
PUT museums
26+
{
27+
"mappings": {
28+
"properties": {
29+
"location": {
30+
"type": "geo_point"
31+
},
32+
"name": {
33+
"type": "keyword"
34+
},
35+
"price": {
36+
"type": "long"
37+
},
38+
"included": {
39+
"type": "boolean"
40+
}
41+
}
42+
}
43+
}
44+
45+
POST museums/_bulk?refresh
46+
{ "index": { "_id": "1" } }
47+
{ "location": "POINT (4.912350 52.374081)", "name": "NEMO Science Museum", "price": 1750, "included": true }
48+
{ "index": { "_id": "2" } }
49+
{ "location": "POINT (4.901618 52.369219)", "name": "Museum Het Rembrandthuis", "price": 1500, "included": false }
50+
{ "index": { "_id": "3" } }
51+
{ "location": "POINT (4.914722 52.371667)", "name": "Nederlands Scheepvaartmuseum", "price":1650, "included": true }
52+
{ "index": { "_id": "4" } }
53+
{ "location": "POINT (4.914722 52.371667)", "name": "Amsterdam Centre for Architecture", "price":0, "included": true }
54+
```
55+
56+
## Query a vector tile for geospatial data
57+
58+
The following request searches the index for `location` values that intersect
59+
the `13/4207/2692` vector tile.
60+
61+
```console
62+
GET museums/_mvt/location/13/4207/2692
63+
{
64+
"grid_agg": "geotile",
65+
"grid_precision": 2,
66+
"fields": [
67+
"name",
68+
"price"
69+
],
70+
"query": {
71+
"term": {
72+
"included": true
73+
}
74+
},
75+
"aggs": {
76+
"min_price": {
77+
"min": {
78+
"field": "price"
79+
}
80+
},
81+
"max_price": {
82+
"max": {
83+
"field": "price"
84+
}
85+
},
86+
"avg_price": {
87+
"avg": {
88+
"field": "price"
89+
}
90+
}
91+
}
92+
}
93+
```
94+
% TEST[continued]
95+
96+
## Example response
97+
98+
The API returns results as a binary vector tile. When decoded into JSON, the
99+
tile contains the following data:
100+
101+
```js
102+
{
103+
"hits": {
104+
"extent": 4096,
105+
"version": 2,
106+
"features": [
107+
{
108+
"geometry": {
109+
"type": "Point",
110+
"coordinates": [
111+
3208,
112+
3864
113+
]
114+
},
115+
"properties": {
116+
"_id": "1",
117+
"_index": "museums",
118+
"name": "NEMO Science Museum",
119+
"price": 1750
120+
},
121+
"type": 1
122+
},
123+
{
124+
"geometry": {
125+
"type": "Point",
126+
"coordinates": [
127+
3429,
128+
3496
129+
]
130+
},
131+
"properties": {
132+
"_id": "3",
133+
"_index": "museums",
134+
"name": "Nederlands Scheepvaartmuseum",
135+
"price": 1650
136+
},
137+
"type": 1
138+
},
139+
{
140+
"geometry": {
141+
"type": "Point",
142+
"coordinates": [
143+
3429,
144+
3496
145+
]
146+
},
147+
"properties": {
148+
"_id": "4",
149+
"_index": "museums",
150+
"name": "Amsterdam Centre for Architecture",
151+
"price": 0
152+
},
153+
"type": 1
154+
}
155+
]
156+
},
157+
"aggs": {
158+
"extent": 4096,
159+
"version": 2,
160+
"features": [
161+
{
162+
"geometry": {
163+
"type": "Polygon",
164+
"coordinates": [
165+
[
166+
[
167+
3072,
168+
3072
169+
],
170+
[
171+
4096,
172+
3072
173+
],
174+
[
175+
4096,
176+
4096
177+
],
178+
[
179+
3072,
180+
4096
181+
],
182+
[
183+
3072,
184+
3072
185+
]
186+
]
187+
]
188+
},
189+
"properties": {
190+
"_count": 3,
191+
"max_price.value": 1750.0,
192+
"min_price.value": 0.0,
193+
"avg_price.value": 1133.3333333333333
194+
},
195+
"type": 3
196+
}
197+
]
198+
},
199+
"meta": {
200+
"extent": 4096,
201+
"version": 2,
202+
"features": [
203+
{
204+
"geometry": {
205+
"type": "Polygon",
206+
"coordinates": [
207+
[
208+
[
209+
0,
210+
0
211+
],
212+
[
213+
4096,
214+
0
215+
],
216+
[
217+
4096,
218+
4096
219+
],
220+
[
221+
0,
222+
4096
223+
],
224+
[
225+
0,
226+
0
227+
]
228+
]
229+
]
230+
},
231+
"properties": {
232+
"_shards.failed": 0,
233+
"_shards.skipped": 0,
234+
"_shards.successful": 1,
235+
"_shards.total": 1,
236+
"aggregations._count.avg": 3.0,
237+
"aggregations._count.count": 1,
238+
"aggregations._count.max": 3.0,
239+
"aggregations._count.min": 3.0,
240+
"aggregations._count.sum": 3.0,
241+
"aggregations.avg_price.avg": 1133.3333333333333,
242+
"aggregations.avg_price.count": 1,
243+
"aggregations.avg_price.max": 1133.3333333333333,
244+
"aggregations.avg_price.min": 1133.3333333333333,
245+
"aggregations.avg_price.sum": 1133.3333333333333,
246+
"aggregations.max_price.avg": 1750.0,
247+
"aggregations.max_price.count": 1,
248+
"aggregations.max_price.max": 1750.0,
249+
"aggregations.max_price.min": 1750.0,
250+
"aggregations.max_price.sum": 1750.0,
251+
"aggregations.min_price.avg": 0.0,
252+
"aggregations.min_price.count": 1,
253+
"aggregations.min_price.max": 0.0,
254+
"aggregations.min_price.min": 0.0,
255+
"aggregations.min_price.sum": 0.0,
256+
"hits.max_score": 0.0,
257+
"hits.total.relation": "eq",
258+
"hits.total.value": 3,
259+
"timed_out": false,
260+
"took": 2
261+
},
262+
"type": 3
263+
}
264+
]
265+
}
266+
}
267+
```
268+
% NOTCONSOLE
269+

0 commit comments

Comments
 (0)