6
6
7
7
Filter documents indexed using the `geo_shape` or `geo_point` type.
8
8
9
- Requires the <<geo-shape,`geo_shape` Mapping>> or the <<geo-point,`geo_point` Mapping>>.
9
+ Requires the <<geo-shape,`geo_shape` Mapping>> or the
10
+ <<geo-point,`geo_point` Mapping>>.
10
11
11
12
The `geo_shape` query uses the same grid square representation as the
12
13
`geo_shape` mapping to find documents that have a shape that intersects
@@ -18,6 +19,7 @@ providing a whole shape definition, or by referencing the name of a shape
18
19
pre-indexed in another index. Both formats are defined below with
19
20
examples.
20
21
22
+
21
23
==== Inline Shape Definition
22
24
23
25
Similar to the `geo_shape` type, the `geo_shape` query uses
@@ -49,8 +51,9 @@ POST /example/_doc?refresh
49
51
--------------------------------------------------
50
52
// TESTSETUP
51
53
52
- The following query will find the point using the Elasticsearch's
53
- `envelope` GeoJSON extension:
54
+
55
+ The following query will find the point using {es}'s `envelope` GeoJSON
56
+ extension:
54
57
55
58
[source,console]
56
59
--------------------------------------------------
@@ -77,6 +80,7 @@ GET /example/_search
77
80
}
78
81
--------------------------------------------------
79
82
83
+
80
84
The above query can, similarly, be queried on `geo_point` fields.
81
85
82
86
[source,console]
@@ -100,7 +104,9 @@ PUT /example_points/_doc/1?refresh
100
104
--------------------------------------------------
101
105
// TEST[continued]
102
106
103
- Using the same query, the documents with matching `geo_point` fields are returned
107
+
108
+ Using the same query, the documents with matching `geo_point` fields are
109
+ returned.
104
110
105
111
[source,console]
106
112
--------------------------------------------------
@@ -162,19 +168,19 @@ GET /example_points/_search
162
168
--------------------------------------------------
163
169
// TESTRESPONSE[s/"took" : 17/"took" : $body.took/]
164
170
171
+
165
172
==== Pre-Indexed Shape
166
173
167
- The Query also supports using a shape which has already been indexed in
168
- another index. This is particularly useful for when
169
- you have a pre-defined list of shapes which are useful to your
170
- application and you want to reference this using a logical name (for
171
- example 'New Zealand') rather than having to provide their coordinates
172
- each time. In this situation it is only necessary to provide:
174
+ The query also supports using a shape which has already been indexed in another
175
+ index. This is particularly useful for when you have a pre-defined list of
176
+ shapes and you want to reference the list using
177
+ a logical name (for example 'New Zealand') rather than having to provide
178
+ coordinates each time. In this situation, it is only necessary to provide:
173
179
174
180
* `id` - The ID of the document that containing the pre-indexed shape.
175
- * `index` - Name of the index where the pre-indexed shape is. Defaults
176
- to 'shapes'.
177
- * `path` - The field specified as path containing the pre-indexed shape.
181
+ * `index` - Name of the index where the pre-indexed shape is. Defaults to
182
+ 'shapes'.
183
+ * `path` - The field specified as path containing the pre-indexed shape.
178
184
Defaults to 'shape'.
179
185
* `routing` - The routing of the shape document if required.
180
186
@@ -222,27 +228,31 @@ GET /example/_search
222
228
}
223
229
--------------------------------------------------
224
230
231
+
225
232
==== Spatial Relations
226
233
227
- The <<spatial-strategy, geo_shape strategy>> mapping parameter determines
228
- which spatial relation operators may be used at search time.
234
+ The <<spatial-strategy, geo_shape strategy>> mapping parameter determines which
235
+ spatial relation operators may be used at search time.
229
236
230
- The following is a complete list of spatial relation operators available when searching a field of type `geo_shape`:
237
+ The following is a complete list of spatial relation operators available when
238
+ searching a field of type `geo_shape`:
231
239
232
240
* `INTERSECTS` - (default) Return all documents whose `geo_shape` field
233
241
intersects the query geometry.
234
- * `DISJOINT` - Return all documents whose `geo_shape` field
235
- has nothing in common with the query geometry.
236
- * `WITHIN` - Return all documents whose `geo_shape` field
237
- is within the query geometry.
238
- * `CONTAINS` - Return all documents whose `geo_shape` field
239
- contains the query geometry.
242
+ * `DISJOINT` - Return all documents whose `geo_shape` field has nothing in
243
+ common with the query geometry.
244
+ * `WITHIN` - Return all documents whose `geo_shape` field is within the query
245
+ geometry.
246
+ * `CONTAINS` - Return all documents whose `geo_shape` field contains the query
247
+ geometry.
240
248
241
- When searching a field of type `geo_point` there is a single supported spatial relation operator:
249
+ When searching a field of type `geo_point` there is a single supported spatial
250
+ relation operator:
242
251
243
- * `INTERSECTS` - (default) Return all documents whose `geo_point` field
252
+ * `INTERSECTS` - (default) Return all documents whose `geo_point` field
244
253
intersects the query geometry.
245
254
255
+
246
256
[float]
247
257
==== Ignore Unmapped
248
258
@@ -252,15 +262,55 @@ querying multiple indexes which might have different mappings. When set to
252
262
`false` (the default value) the query will throw an exception if the field
253
263
is not mapped.
254
264
265
+
255
266
==== Shape Types supported for Geo-Point
256
267
257
- When searching a field of type `geo_point` the following shape types are not supported:
268
+ When searching a field of type `geo_point` the following shape types are not
269
+ supported:
258
270
259
271
* `POINT`
260
272
* `LINE`
261
273
* `MULTIPOINT`
262
274
* `MULTILINE`
263
275
264
276
==== Notes
265
- Geo-shape queries on geo-shapes implemented with <<prefix-trees, `PrefixTrees`>> will not be executed if
266
- <<query-dsl-allow-expensive-queries, `search.allow_expensive_queries`>> is set to false.
277
+
278
+ * Geo-shape queries on geo-shapes implemented with
279
+ <<prefix-trees, `PrefixTrees`>> will not be executed if
280
+ <<query-dsl-allow-expensive-queries, `search.allow_expensive_queries`>> is set
281
+ to false.
282
+
283
+
284
+ * When data is indexed in a `geo_shape` field as an array of shapes, the arrays
285
+ are treated as one shape. For this reason, the following requests are
286
+ equivalent.
287
+
288
+ [source,console]
289
+ --------------------------------------------------
290
+ PUT /test/_doc/1
291
+ {
292
+ "location": [
293
+ {
294
+ "coordinates": [46.25,20.14],
295
+ "type": "point"
296
+ },
297
+ {
298
+ "coordinates": [47.49,19.04],
299
+ "type": "point"
300
+ }
301
+ ]
302
+ }
303
+ --------------------------------------------------
304
+
305
+
306
+ [source,console]
307
+ --------------------------------------------------
308
+ PUT /test/_doc/1
309
+ {
310
+ "location":
311
+ {
312
+ "coordinates": [[46.25,20.14],[47.49,19.04]],
313
+ "type": "multipoint"
314
+ }
315
+ }
316
+ --------------------------------------------------
0 commit comments