2015-05-05 02:27:52 -04:00
|
|
|
[[query-dsl-geo-shape-query]]
|
2019-07-18 10:18:11 -04:00
|
|
|
=== Geo-shape query
|
|
|
|
++++
|
|
|
|
<titleabbrev>Geo-shape</titleabbrev>
|
|
|
|
++++
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2020-03-19 08:00:36 -04:00
|
|
|
Filter documents indexed using the `geo_shape` or `geo_point` type.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2020-06-08 09:03:59 -04:00
|
|
|
Requires the <<geo-shape,`geo_shape` Mapping>> or the
|
|
|
|
<<geo-point,`geo_point` 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
|
2017-03-30 22:37:57 -04:00
|
|
|
`geo_shape` mapping to find documents that have a shape that intersects
|
[Geo] Integrate Lucene's LatLonShape (BKD Backed GeoShapes) as default `geo_shape` indexing approach (#36751)
* [Geo] Expose BKDBackedGeoShapes as new VECTOR strategy
This commit exposes lucene's LatLonShape field as a new
strategy in GeoShapeFieldMapper. To use the new indexing
approach, strategy should be set to "vector" in the
geo_shape field mapper. If the tree parameter is set
the mapper will throw an IAE. Note the following:
When using vector strategy:
* geo_shape query does not support querying by POINT,
MULTIPOINT, or GEOMETRYCOLLECTION.
* LINESTRING and MULTILINESTRING queries do not support
WITHIN relation.
* CONTAINS relation is not supported.
* The tree, precision, tree_levels, distance_error_pct,
and points_only parameters will not throw an exception
but they have no effect and will be marked as
deprecated..
All other features are supported.
* revert change to PercolatorFieldMapper
* fix ExistsQuery for geo_shape vector strategy
* add deprecation logging for tree, precision, tree_levels, distance_error_pct, and points_only
* initial update to geoshape docs, including mapping migration updates
* initial support for GeoCollection queries
* fix docs and javadoc errors
* clean up geocollection queries
* set deprecated mapping tests to NOTCONSOLE
* fix geo-shape mapper asciidoc mapping and test warnings
* add support for point queries using LatLonShapeBoundingBoxQuery
* update GeoShapeQueryBuilderTests to include POINT queries for VECTOR strategy. Other comment cleanups
* add lucene geometry build testing to ShapeBuilder tests
* remove deprecated prefix tree mapping from geo-shape.asciidoc
* refactor GeoShapeFieldMapper into LegacyGeoShapeFieldMapper and GeoShapeFieldMapper
Both classes derive from BaseGeoShapeFieldMapper that provides shared parameters:
coerce, ignoreMalformed, ignore_z_value, orientation.
* update docs to remove vector strategy
* fix GeometryCollectionBuilder#buildLucene to return the object created by the shape builder
* fix LineLength failure in GeoJsonShapeParserTests
* ShapeMapper refactor changes from PR feedback
* fix typo in geo-shape.asciidoc
* ignore circle test in docs
* update indexing-approach ref to geoshape-indexing-approach
* add warnings check for LegacyGeoShapeFieldMapper to AbstractBuilderTestCase
* fix deprecatedParameters setup
* update indexing approach
* fixing unexpected warnings failures
* move orientation back to field type
* remove if in LegacyGeoShapeFieldMapper#doXContent. Fix GeoShapeFieldMapper to work with double array as a point
* fix indexing-approach link in circle section of geoshape docs
* add strategy to deprecation warnings check
* fix test failures
* fix typo in QueryStringQueryBuilderTests
* fix total hits to totalHits().value
* fix version number
* add version check to BaseGeoShapeFieldMapper
* fix line length!
* revert version check in BaseGeoShapeFieldMapper
* Fix serialization of mappings of legacy shapes.
2018-12-18 10:54:56 -05:00
|
|
|
with the query shape. It will also use the same Prefix Tree configuration
|
2013-08-28 19:24:34 -04:00
|
|
|
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.
|
|
|
|
|
2020-06-08 09:03:59 -04:00
|
|
|
|
2015-06-04 07:16:32 -04:00
|
|
|
==== Inline Shape Definition
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2017-03-30 22:37:57 -04:00
|
|
|
Similar to the `geo_shape` type, the `geo_shape` query uses
|
2013-08-28 19:24:34 -04:00
|
|
|
http://www.geojson.org[GeoJSON] to represent shapes.
|
|
|
|
|
2020-06-02 15:56:13 -04:00
|
|
|
Given the following index with locations as `geo_shape` fields:
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2019-01-22 09:13:52 -05:00
|
|
|
PUT /example
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"mappings": {
|
|
|
|
"properties": {
|
|
|
|
"location": {
|
|
|
|
"type": "geo_shape"
|
|
|
|
}
|
2017-03-30 22:37:57 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2017-03-30 22:37:57 -04:00
|
|
|
}
|
|
|
|
|
2017-12-14 11:47:53 -05:00
|
|
|
POST /example/_doc?refresh
|
2017-03-30 22:37:57 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"name": "Wind & Wetter, Berlin, Germany",
|
|
|
|
"location": {
|
|
|
|
"type": "point",
|
|
|
|
"coordinates": [ 13.400544, 52.530286 ]
|
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2017-03-30 22:37:57 -04:00
|
|
|
// TESTSETUP
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2020-06-08 09:03:59 -04:00
|
|
|
|
|
|
|
The following query will find the point using {es}'s `envelope` GeoJSON
|
|
|
|
extension:
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2017-03-30 22:37:57 -04:00
|
|
|
GET /example/_search
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"query": {
|
|
|
|
"bool": {
|
|
|
|
"must": {
|
|
|
|
"match_all": {}
|
|
|
|
},
|
|
|
|
"filter": {
|
|
|
|
"geo_shape": {
|
|
|
|
"location": {
|
|
|
|
"shape": {
|
|
|
|
"type": "envelope",
|
|
|
|
"coordinates": [ [ 13.0, 53.0 ], [ 14.0, 52.0 ] ]
|
2013-08-28 19:24:34 -04:00
|
|
|
},
|
2020-07-21 15:49:58 -04:00
|
|
|
"relation": "within"
|
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2020-06-08 09:03:59 -04:00
|
|
|
|
2020-06-02 15:56:13 -04:00
|
|
|
The above query can, similarly, be queried on `geo_point` fields.
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
--------------------------------------------------
|
|
|
|
PUT /example_points
|
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"mappings": {
|
|
|
|
"properties": {
|
|
|
|
"location": {
|
|
|
|
"type": "geo_point"
|
|
|
|
}
|
2020-06-02 15:56:13 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2020-06-02 15:56:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
PUT /example_points/_doc/1?refresh
|
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"name": "Wind & Wetter, Berlin, Germany",
|
|
|
|
"location": [13.400544, 52.530286]
|
2020-06-02 15:56:13 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[continued]
|
|
|
|
|
2020-06-08 09:03:59 -04:00
|
|
|
|
|
|
|
Using the same query, the documents with matching `geo_point` fields are
|
|
|
|
returned.
|
2020-06-02 15:56:13 -04:00
|
|
|
|
|
|
|
[source,console]
|
|
|
|
--------------------------------------------------
|
|
|
|
GET /example_points/_search
|
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"query": {
|
|
|
|
"bool": {
|
|
|
|
"must": {
|
|
|
|
"match_all": {}
|
|
|
|
},
|
|
|
|
"filter": {
|
|
|
|
"geo_shape": {
|
|
|
|
"location": {
|
|
|
|
"shape": {
|
|
|
|
"type": "envelope",
|
|
|
|
"coordinates": [ [ 13.0, 53.0 ], [ 14.0, 52.0 ] ]
|
2020-06-02 15:56:13 -04:00
|
|
|
},
|
2020-07-21 15:49:58 -04:00
|
|
|
"relation": "intersects"
|
|
|
|
}
|
2020-06-02 15:56:13 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2020-06-02 15:56:13 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2020-06-02 15:56:13 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[continued]
|
|
|
|
|
|
|
|
[source,console-result]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"took" : 17,
|
|
|
|
"timed_out" : false,
|
|
|
|
"_shards" : {
|
|
|
|
"total" : 1,
|
|
|
|
"successful" : 1,
|
|
|
|
"skipped" : 0,
|
|
|
|
"failed" : 0
|
|
|
|
},
|
|
|
|
"hits" : {
|
|
|
|
"total" : {
|
|
|
|
"value" : 1,
|
|
|
|
"relation" : "eq"
|
|
|
|
},
|
|
|
|
"max_score" : 1.0,
|
|
|
|
"hits" : [
|
|
|
|
{
|
|
|
|
"_index" : "example_points",
|
2020-06-02 16:44:08 -04:00
|
|
|
"_type" : "_doc",
|
2020-06-02 15:56:13 -04:00
|
|
|
"_id" : "1",
|
|
|
|
"_score" : 1.0,
|
|
|
|
"_source" : {
|
|
|
|
"name": "Wind & Wetter, Berlin, Germany",
|
|
|
|
"location": [13.400544, 52.530286]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// TESTRESPONSE[s/"took" : 17/"took" : $body.took/]
|
|
|
|
|
2020-06-08 09:03:59 -04:00
|
|
|
|
2015-06-04 07:16:32 -04:00
|
|
|
==== Pre-Indexed Shape
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2020-06-08 09:03:59 -04:00
|
|
|
The query also supports using a shape which has already been indexed in another
|
|
|
|
index. This is particularly useful for when you have a pre-defined list of
|
|
|
|
shapes and you want to reference the list using
|
|
|
|
a logical name (for example 'New Zealand') rather than having to provide
|
|
|
|
coordinates each time. In this situation, it is only necessary to provide:
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
* `id` - The ID of the document that containing the pre-indexed shape.
|
2020-06-08 09:03:59 -04:00
|
|
|
* `index` - Name of the index where the pre-indexed shape is. Defaults to
|
|
|
|
'shapes'.
|
|
|
|
* `path` - The field specified as path containing the pre-indexed shape.
|
2013-12-23 05:27:06 -05:00
|
|
|
Defaults to 'shape'.
|
2018-05-23 15:15:19 -04:00
|
|
|
* `routing` - The routing of the shape document if required.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
The following is an example of using the Filter with a pre-indexed
|
|
|
|
shape:
|
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2019-01-22 09:13:52 -05:00
|
|
|
PUT /shapes
|
2017-03-30 22:37:57 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"mappings": {
|
|
|
|
"properties": {
|
|
|
|
"location": {
|
|
|
|
"type": "geo_shape"
|
|
|
|
}
|
2017-03-30 22:37:57 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2017-03-30 22:37:57 -04:00
|
|
|
}
|
|
|
|
|
2017-12-14 11:47:53 -05:00
|
|
|
PUT /shapes/_doc/deu
|
2017-03-30 22:37:57 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"location": {
|
|
|
|
"type": "envelope",
|
|
|
|
"coordinates" : [[13.0, 53.0], [14.0, 52.0]]
|
|
|
|
}
|
2017-03-30 22:37:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
GET /example/_search
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"query": {
|
|
|
|
"bool": {
|
|
|
|
"filter": {
|
|
|
|
"geo_shape": {
|
|
|
|
"location": {
|
|
|
|
"indexed_shape": {
|
|
|
|
"index": "shapes",
|
|
|
|
"id": "deu",
|
|
|
|
"path": "location"
|
2017-03-30 22:37:57 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2020-06-08 09:03:59 -04:00
|
|
|
|
2015-11-17 15:28:12 -05:00
|
|
|
==== Spatial Relations
|
|
|
|
|
2020-06-08 09:03:59 -04:00
|
|
|
The <<spatial-strategy, geo_shape strategy>> mapping parameter determines which
|
|
|
|
spatial relation operators may be used at search time.
|
2015-12-02 11:09:00 -05:00
|
|
|
|
2020-06-08 09:03:59 -04:00
|
|
|
The following is a complete list of spatial relation operators available when
|
|
|
|
searching a field of type `geo_shape`:
|
2015-11-17 15:28:12 -05:00
|
|
|
|
|
|
|
* `INTERSECTS` - (default) Return all documents whose `geo_shape` field
|
|
|
|
intersects the query geometry.
|
2020-06-08 09:03:59 -04:00
|
|
|
* `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 contains the query
|
|
|
|
geometry.
|
2016-04-14 06:38:48 -04:00
|
|
|
|
2020-06-08 09:03:59 -04:00
|
|
|
When searching a field of type `geo_point` there is a single supported spatial
|
|
|
|
relation operator:
|
2020-03-19 08:00:36 -04:00
|
|
|
|
2020-06-08 09:03:59 -04:00
|
|
|
* `INTERSECTS` - (default) Return all documents whose `geo_point` field
|
2020-03-19 08:00:36 -04:00
|
|
|
intersects the query geometry.
|
|
|
|
|
2020-06-08 09:03:59 -04:00
|
|
|
|
2016-04-14 06:38:48 -04:00
|
|
|
[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.
|
2020-02-12 16:56:14 -05:00
|
|
|
|
2020-06-08 09:03:59 -04:00
|
|
|
|
2020-03-19 08:00:36 -04:00
|
|
|
==== Shape Types supported for Geo-Point
|
|
|
|
|
2020-06-08 09:03:59 -04:00
|
|
|
When searching a field of type `geo_point` the following shape types are not
|
|
|
|
supported:
|
2020-03-19 08:00:36 -04:00
|
|
|
|
|
|
|
* `POINT`
|
|
|
|
* `LINE`
|
|
|
|
* `MULTIPOINT`
|
|
|
|
* `MULTILINE`
|
|
|
|
|
2020-02-12 16:56:14 -05:00
|
|
|
==== Notes
|
2020-06-08 09:03:59 -04:00
|
|
|
|
|
|
|
* Geo-shape queries on geo-shapes implemented with
|
|
|
|
<<prefix-trees, `PrefixTrees`>> will not be executed if
|
|
|
|
<<query-dsl-allow-expensive-queries, `search.allow_expensive_queries`>> is set
|
|
|
|
to false.
|
|
|
|
|
|
|
|
|
|
|
|
* When data is indexed in a `geo_shape` field as an array of shapes, the arrays
|
|
|
|
are treated as one shape. For this reason, the following requests are
|
|
|
|
equivalent.
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
--------------------------------------------------
|
|
|
|
PUT /test/_doc/1
|
|
|
|
{
|
|
|
|
"location": [
|
|
|
|
{
|
|
|
|
"coordinates": [46.25,20.14],
|
|
|
|
"type": "point"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"coordinates": [47.49,19.04],
|
|
|
|
"type": "point"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
[source,console]
|
|
|
|
--------------------------------------------------
|
|
|
|
PUT /test/_doc/1
|
|
|
|
{
|
|
|
|
"location":
|
|
|
|
{
|
|
|
|
"coordinates": [[46.25,20.14],[47.49,19.04]],
|
|
|
|
"type": "multipoint"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|