Skip to content

Commit 971916f

Browse files
szabostevejrodewig
andcommitted
[DOCS] Extends geo_shape query docs to explain behavior when data is indexed as array of shapes (#57806)
Co-authored-by: James Rodewig <[email protected]>
1 parent bf20b75 commit 971916f

File tree

1 file changed

+77
-27
lines changed

1 file changed

+77
-27
lines changed

docs/reference/query-dsl/geo-shape-query.asciidoc

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
Filter documents indexed using the `geo_shape` or `geo_point` type.
88

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>>.
1011

1112
The `geo_shape` query uses the same grid square representation as the
1213
`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
1819
pre-indexed in another index. Both formats are defined below with
1920
examples.
2021

22+
2123
==== Inline Shape Definition
2224

2325
Similar to the `geo_shape` type, the `geo_shape` query uses
@@ -49,8 +51,9 @@ POST /example/_doc?refresh
4951
--------------------------------------------------
5052
// TESTSETUP
5153

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:
5457

5558
[source,console]
5659
--------------------------------------------------
@@ -77,6 +80,7 @@ GET /example/_search
7780
}
7881
--------------------------------------------------
7982

83+
8084
The above query can, similarly, be queried on `geo_point` fields.
8185

8286
[source,console]
@@ -100,7 +104,9 @@ PUT /example_points/_doc/1?refresh
100104
--------------------------------------------------
101105
// TEST[continued]
102106

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.
104110

105111
[source,console]
106112
--------------------------------------------------
@@ -162,19 +168,19 @@ GET /example_points/_search
162168
--------------------------------------------------
163169
// TESTRESPONSE[s/"took" : 17/"took" : $body.took/]
164170

171+
165172
==== Pre-Indexed Shape
166173

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:
173179

174180
* `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.
178184
Defaults to 'shape'.
179185
* `routing` - The routing of the shape document if required.
180186

@@ -222,27 +228,31 @@ GET /example/_search
222228
}
223229
--------------------------------------------------
224230

231+
225232
==== Spatial Relations
226233

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.
229236

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`:
231239

232240
* `INTERSECTS` - (default) Return all documents whose `geo_shape` field
233241
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.
240248

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:
242251

243-
* `INTERSECTS` - (default) Return all documents whose `geo_point` field
252+
* `INTERSECTS` - (default) Return all documents whose `geo_point` field
244253
intersects the query geometry.
245254

255+
246256
[float]
247257
==== Ignore Unmapped
248258

@@ -252,15 +262,55 @@ querying multiple indexes which might have different mappings. When set to
252262
`false` (the default value) the query will throw an exception if the field
253263
is not mapped.
254264

265+
255266
==== Shape Types supported for Geo-Point
256267

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:
258270

259271
* `POINT`
260272
* `LINE`
261273
* `MULTIPOINT`
262274
* `MULTILINE`
263275

264276
==== 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

Comments
 (0)