Skip to content

Commit

Permalink
Update geo_point docs for geo_shape queries
Browse files Browse the repository at this point in the history
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 elastic#56927.
  • Loading branch information
talevy committed Jun 1, 2020
1 parent 0f078e0 commit 6b2590a
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/reference/mapping/types/geo-point.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Fields of type `geo_point` accept latitude-longitude pairs, which can be used:

* to find geo-points within a <<query-dsl-geo-bounding-box-query,bounding box>>,
within a certain <<query-dsl-geo-distance-query,distance>> of a central point,
or within a <<query-dsl-geo-polygon-query,polygon>>.
or within a <<query-dsl-geo-polygon-query,polygon>> or within a <<query-dsl-geo-shape-query,geo_shape query>>.
* to aggregate documents <<search-aggregations-bucket-geohashgrid-aggregation,geographically>>
or by <<search-aggregations-bucket-geodistance-aggregation,distance>> from a central point.
* to integrate distance into a document's <<query-dsl-function-score-query,relevance score>>.
Expand Down
85 changes: 84 additions & 1 deletion docs/reference/query-dsl/geo-shape-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
--------------------------------------------------
Expand Down Expand Up @@ -77,6 +77,89 @@ GET /example/_search
}
--------------------------------------------------

The above query can, similarly, be queried on `geo_point` fields.

[source,console]
--------------------------------------------------
PUT /example
{
"mappings": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
POST /example/_doc?refresh
{
"name": "Wind & Wetter, Berlin, Germany",
"location": [13.400544, 52.530286]
}
--------------------------------------------------
// TESTSETUP

Using the same query, the documents with matching `geo_point` fields are returned

[source,console]
--------------------------------------------------
GET /example/_search
{
"query":{
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_shape": {
"location": {
"shape": {
"type": "envelope",
"coordinates" : [[13.0, 53.0], [14.0, 52.0]]
},
"relation": "within"
}
}
}
}
}
}
--------------------------------------------------

[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",
"_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
Expand Down

0 comments on commit 6b2590a

Please sign in to comment.