2015-05-05 02:27:52 -04:00
|
|
|
[[query-dsl-geo-shape-query]]
|
2015-06-04 07:16:32 -04:00
|
|
|
=== GeoShape Query
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
Filter documents indexed using the `geo_shape` type.
|
|
|
|
|
2015-08-06 11:24:29 -04:00
|
|
|
Requires the <<geo-shape,`geo_shape` Mapping>>.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-05-05 02:27:52 -04:00
|
|
|
The `geo_shape` query uses the same grid square representation as the
|
2013-08-28 19:24:34 -04:00
|
|
|
geo_shape mapping to find documents that have a shape that intersects
|
|
|
|
with the query shape. It will also use the same PrefixTree configuration
|
|
|
|
as defined for the field mapping.
|
|
|
|
|
2015-06-04 07:16:32 -04:00
|
|
|
The query supports two ways of defining the query shape, either by
|
2014-11-02 18:36:06 -05:00
|
|
|
providing a whole shape definition, or by referencing the name of a shape
|
2013-08-28 19:24:34 -04:00
|
|
|
pre-indexed in another index. Both formats are defined below with
|
|
|
|
examples.
|
|
|
|
|
2015-06-04 07:16:32 -04:00
|
|
|
==== Inline Shape Definition
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
Similar to the `geo_shape` type, the `geo_shape` Filter uses
|
|
|
|
http://www.geojson.org[GeoJSON] to represent shapes.
|
|
|
|
|
|
|
|
Given a document that looks like this:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"name": "Wind & Wetter, Berlin, Germany",
|
|
|
|
"location": {
|
|
|
|
"type": "Point",
|
|
|
|
"coordinates": [13.400544, 52.530286]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
The following query will find the point using the Elasticsearch's
|
|
|
|
`envelope` GeoJSON extension:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"query":{
|
2015-09-11 04:35:56 -04:00
|
|
|
"bool": {
|
|
|
|
"must": {
|
2013-08-28 19:24:34 -04:00
|
|
|
"match_all": {}
|
|
|
|
},
|
|
|
|
"filter": {
|
|
|
|
"geo_shape": {
|
|
|
|
"location": {
|
|
|
|
"shape": {
|
|
|
|
"type": "envelope",
|
|
|
|
"coordinates" : [[13.0, 53.0], [14.0, 52.0]]
|
2015-11-17 15:28:12 -05:00
|
|
|
},
|
|
|
|
"relation": "within"
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2015-06-04 07:16:32 -04:00
|
|
|
==== Pre-Indexed Shape
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-11-17 15:28:12 -05:00
|
|
|
The Query also supports using a shape which has already been indexed in
|
2013-08-28 19:24:34 -04:00
|
|
|
another index and/or index type. This is particularly useful for when
|
|
|
|
you have a pre-defined list of shapes which are useful to your
|
|
|
|
application and you want to reference this using a logical name (for
|
|
|
|
example 'New Zealand') rather than having to provide their coordinates
|
|
|
|
each time. In this situation it is only necessary to provide:
|
|
|
|
|
|
|
|
* `id` - The ID of the document that containing the pre-indexed shape.
|
|
|
|
* `index` - Name of the index where the pre-indexed shape is. Defaults
|
|
|
|
to 'shapes'.
|
|
|
|
* `type` - Index type where the pre-indexed shape is.
|
2013-12-23 05:27:06 -05:00
|
|
|
* `path` - The field specified as path containing the pre-indexed shape.
|
|
|
|
Defaults to 'shape'.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
The following is an example of using the Filter with a pre-indexed
|
|
|
|
shape:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
2015-09-11 04:35:56 -04:00
|
|
|
"bool": {
|
|
|
|
"must": {
|
2013-08-28 19:24:34 -04:00
|
|
|
"match_all": {}
|
|
|
|
},
|
|
|
|
"filter": {
|
|
|
|
"geo_shape": {
|
|
|
|
"location": {
|
|
|
|
"indexed_shape": {
|
|
|
|
"id": "DEU",
|
|
|
|
"type": "countries",
|
|
|
|
"index": "shapes",
|
2013-12-23 05:27:06 -05:00
|
|
|
"path": "location"
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2015-11-17 15:28:12 -05:00
|
|
|
==== Spatial Relations
|
|
|
|
|
2015-12-02 11:09:00 -05:00
|
|
|
The <<spatial-strategy, geo_shape strategy>> mapping parameter determines
|
|
|
|
which spatial relation operators may be used at search time.
|
|
|
|
|
|
|
|
The following is a complete list of spatial relation operators available:
|
2015-11-17 15:28:12 -05:00
|
|
|
|
|
|
|
* `INTERSECTS` - (default) Return all documents whose `geo_shape` field
|
|
|
|
intersects the query geometry.
|
|
|
|
* `DISJOINT` - Return all documents whose `geo_shape` field
|
|
|
|
has nothing in common with the query geometry.
|
|
|
|
* `WITHIN` - Return all documents whose `geo_shape` field
|
|
|
|
is within the query geometry.
|
|
|
|
* `CONTAINS` - Return all documents whose `geo_shape` field
|
2016-04-14 06:38:48 -04:00
|
|
|
contains the query geometry.
|
|
|
|
|
|
|
|
[float]
|
|
|
|
==== Ignore Unmapped
|
|
|
|
|
|
|
|
When set to `true` the `ignore_unmapped` option will ignore an unmapped field
|
|
|
|
and will not match any documents for this query. This can be useful when
|
|
|
|
querying multiple indexes which might have different mappings. When set to
|
|
|
|
`false` (the default value) the query will throw an exception if the field
|
|
|
|
is not mapped.
|