From cfb36c3fccfc52dcb923716cffce537bae8e68bc Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Tue, 2 Jun 2020 12:56:13 -0700 Subject: [PATCH] Update geo_point docs for geo_shape queries (#57487) This commit highlights the ability for geo_point fields to be used in geo_shape queries. It also adds an explicit geo_point example in the geo_shape query documentation Closes #56927. --- .../mapping/types/geo-point.asciidoc | 2 +- .../query-dsl/geo-shape-query.asciidoc | 86 ++++++++++++++++++- 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/docs/reference/mapping/types/geo-point.asciidoc b/docs/reference/mapping/types/geo-point.asciidoc index 2dd90a6ae61a..f109deb0ab38 100644 --- a/docs/reference/mapping/types/geo-point.asciidoc +++ b/docs/reference/mapping/types/geo-point.asciidoc @@ -8,7 +8,7 @@ Fields of type `geo_point` accept latitude-longitude pairs, which can be used: * to find geo-points within a <>, within a certain <> of a central point, - or within a <>. + or within a <> or within a <>. * to aggregate documents <> or by <> from a central point. * to integrate distance into a document's <>. diff --git a/docs/reference/query-dsl/geo-shape-query.asciidoc b/docs/reference/query-dsl/geo-shape-query.asciidoc index 966267d4e353..e605698776ef 100644 --- a/docs/reference/query-dsl/geo-shape-query.asciidoc +++ b/docs/reference/query-dsl/geo-shape-query.asciidoc @@ -23,7 +23,7 @@ examples. Similar to the `geo_shape` type, the `geo_shape` query uses http://www.geojson.org[GeoJSON] to represent shapes. -Given the following index: +Given the following index with locations as `geo_shape` fields: [source,console] -------------------------------------------------- @@ -77,6 +77,90 @@ GET /example/_search } -------------------------------------------------- +The above query can, similarly, be queried on `geo_point` fields. + +[source,console] +-------------------------------------------------- +PUT /example_points +{ + "mappings": { + "properties": { + "location": { + "type": "geo_point" + } + } + } +} + +PUT /example_points/_doc/1?refresh +{ + "name": "Wind & Wetter, Berlin, Germany", + "location": [13.400544, 52.530286] +} +-------------------------------------------------- +// TEST[continued] + +Using the same query, the documents with matching `geo_point` fields are returned + +[source,console] +-------------------------------------------------- +GET /example_points/_search +{ + "query":{ + "bool": { + "must": { + "match_all": {} + }, + "filter": { + "geo_shape": { + "location": { + "shape": { + "type": "envelope", + "coordinates" : [[13.0, 53.0], [14.0, 52.0]] + }, + "relation": "intersects" + } + } + } + } + } +} +-------------------------------------------------- +// 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", + "_id" : "1", + "_score" : 1.0, + "_source" : { + "name": "Wind & Wetter, Berlin, Germany", + "location": [13.400544, 52.530286] + } + } + ] + } +} +-------------------------------------------------- +// TESTRESPONSE[s/"took" : 17/"took" : $body.took/] + ==== Pre-Indexed Shape The Query also supports using a shape which has already been indexed in