-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPATIAL] New ShapeQueryBuilder for querying indexed cartesian geomet…
…ry (#45108) This commit adds a new ShapeQueryBuilder to the xpack spatial module for querying arbitrary Cartesian geometries indexed using the new shape field type. The query builder extends AbstractGeometryQueryBuilder and leverages the ShapeQueryProcessor added in the previous field mapper commit. Tests are provided in ShapeQueryTests in the same manner as GeoShapeQueryTests and docs are updated to explain how the query works.
- Loading branch information
Showing
15 changed files
with
1,296 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[[shape-queries]] | ||
[role="xpack"] | ||
[testenv="basic"] | ||
== Shape queries | ||
|
||
Like <<geo-shape,`geo_shape`>> Elasticsearch supports the ability to index | ||
arbitrary two dimension (non Geospatial) geometries making it possible to | ||
map out virtual worlds, sporting venues, theme parks, and CAD diagrams. The | ||
<<shape,`shape`>> field type supports points, lines, polygons, multi-polygons, | ||
envelope, etc. | ||
|
||
The queries in this group are: | ||
|
||
<<query-dsl-shape-query,`shape`>> query:: | ||
Finds documents with shapes that either intersect, are within, or do not | ||
intersect a specified shape. | ||
|
||
include::shape-query.asciidoc[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
[[query-dsl-shape-query]] | ||
[role="xpack"] | ||
[testenv="basic"] | ||
=== Shape query | ||
++++ | ||
<titleabbrev>Shape</titleabbrev> | ||
++++ | ||
|
||
Queries documents that contain fields indexed using the `shape` type. | ||
|
||
Requires the <<shape,`shape` Mapping>>. | ||
|
||
The query supports two ways of defining the target shape, either by | ||
providing a whole shape definition, or by referencing the name, or id, of a shape | ||
pre-indexed in another index. Both formats are defined below with | ||
examples. | ||
|
||
==== Inline Shape Definition | ||
|
||
Similar to the `geo_shape` query, the `shape` query uses | ||
http://www.geojson.org[GeoJSON] or | ||
https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry[Well Known Text] | ||
(WKT) to represent shapes. | ||
|
||
Given the following index: | ||
|
||
[source,js] | ||
-------------------------------------------------- | ||
PUT /example | ||
{ | ||
"mappings": { | ||
"properties": { | ||
"geometry": { | ||
"type": "shape" | ||
} | ||
} | ||
} | ||
} | ||
POST /example/_doc?refresh | ||
{ | ||
"name": "Lucky Landing", | ||
"location": { | ||
"type": "point", | ||
"coordinates": [1355.400544, 5255.530286] | ||
} | ||
} | ||
-------------------------------------------------- | ||
// CONSOLE | ||
// TESTSETUP | ||
|
||
The following query will find the point using the Elasticsearch's | ||
`envelope` GeoJSON extension: | ||
|
||
[source,js] | ||
-------------------------------------------------- | ||
GET /example/_search | ||
{ | ||
"query":{ | ||
"shape": { | ||
"geometry": { | ||
"shape": { | ||
"type": "envelope", | ||
"coordinates" : [[1355.0, 5355.0], [1400.0, 5200.0]] | ||
}, | ||
"relation": "within" | ||
} | ||
} | ||
} | ||
} | ||
-------------------------------------------------- | ||
// CONSOLE | ||
|
||
==== Pre-Indexed Shape | ||
|
||
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 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'. | ||
* `path` - The field specified as path containing the pre-indexed shape. | ||
Defaults to 'shape'. | ||
* `routing` - The routing of the shape document if required. | ||
|
||
The following is an example of using the Filter with a pre-indexed | ||
shape: | ||
|
||
[source,js] | ||
-------------------------------------------------- | ||
PUT /shapes | ||
{ | ||
"mappings": { | ||
"properties": { | ||
"geometry": { | ||
"type": "shape" | ||
} | ||
} | ||
} | ||
} | ||
PUT /shapes/_doc/footprint | ||
{ | ||
"geometry": { | ||
"type": "envelope", | ||
"coordinates" : [[1355.0, 5355.0], [1400.0, 5200.0]] | ||
} | ||
} | ||
GET /example/_search | ||
{ | ||
"query": { | ||
"shape": { | ||
"geometry": { | ||
"indexed_shape": { | ||
"index": "shapes", | ||
"id": "footprint", | ||
"path": "geometry" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
-------------------------------------------------- | ||
// CONSOLE | ||
|
||
==== Spatial Relations | ||
|
||
The following is a complete list of spatial relation operators available: | ||
|
||
* `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. | ||
|
||
[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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.