Skip to content

Commit cfb36c3

Browse files
authored
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.
1 parent 9479ec1 commit cfb36c3

File tree

2 files changed

+86
-2
lines changed

2 files changed

+86
-2
lines changed

docs/reference/mapping/types/geo-point.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Fields of type `geo_point` accept latitude-longitude pairs, which can be used:
88

99
* to find geo-points within a <<query-dsl-geo-bounding-box-query,bounding box>>,
1010
within a certain <<query-dsl-geo-distance-query,distance>> of a central point,
11-
or within a <<query-dsl-geo-polygon-query,polygon>>.
11+
or within a <<query-dsl-geo-polygon-query,polygon>> or within a <<query-dsl-geo-shape-query,geo_shape query>>.
1212
* to aggregate documents <<search-aggregations-bucket-geohashgrid-aggregation,geographically>>
1313
or by <<search-aggregations-bucket-geodistance-aggregation,distance>> from a central point.
1414
* to integrate distance into a document's <<query-dsl-function-score-query,relevance score>>.

docs/reference/query-dsl/geo-shape-query.asciidoc

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ examples.
2323
Similar to the `geo_shape` type, the `geo_shape` query uses
2424
http://www.geojson.org[GeoJSON] to represent shapes.
2525

26-
Given the following index:
26+
Given the following index with locations as `geo_shape` fields:
2727

2828
[source,console]
2929
--------------------------------------------------
@@ -77,6 +77,90 @@ GET /example/_search
7777
}
7878
--------------------------------------------------
7979

80+
The above query can, similarly, be queried on `geo_point` fields.
81+
82+
[source,console]
83+
--------------------------------------------------
84+
PUT /example_points
85+
{
86+
"mappings": {
87+
"properties": {
88+
"location": {
89+
"type": "geo_point"
90+
}
91+
}
92+
}
93+
}
94+
95+
PUT /example_points/_doc/1?refresh
96+
{
97+
"name": "Wind & Wetter, Berlin, Germany",
98+
"location": [13.400544, 52.530286]
99+
}
100+
--------------------------------------------------
101+
// TEST[continued]
102+
103+
Using the same query, the documents with matching `geo_point` fields are returned
104+
105+
[source,console]
106+
--------------------------------------------------
107+
GET /example_points/_search
108+
{
109+
"query":{
110+
"bool": {
111+
"must": {
112+
"match_all": {}
113+
},
114+
"filter": {
115+
"geo_shape": {
116+
"location": {
117+
"shape": {
118+
"type": "envelope",
119+
"coordinates" : [[13.0, 53.0], [14.0, 52.0]]
120+
},
121+
"relation": "intersects"
122+
}
123+
}
124+
}
125+
}
126+
}
127+
}
128+
--------------------------------------------------
129+
// TEST[continued]
130+
131+
[source,console-result]
132+
--------------------------------------------------
133+
{
134+
"took" : 17,
135+
"timed_out" : false,
136+
"_shards" : {
137+
"total" : 1,
138+
"successful" : 1,
139+
"skipped" : 0,
140+
"failed" : 0
141+
},
142+
"hits" : {
143+
"total" : {
144+
"value" : 1,
145+
"relation" : "eq"
146+
},
147+
"max_score" : 1.0,
148+
"hits" : [
149+
{
150+
"_index" : "example_points",
151+
"_id" : "1",
152+
"_score" : 1.0,
153+
"_source" : {
154+
"name": "Wind & Wetter, Berlin, Germany",
155+
"location": [13.400544, 52.530286]
156+
}
157+
}
158+
]
159+
}
160+
}
161+
--------------------------------------------------
162+
// TESTRESPONSE[s/"took" : 17/"took" : $body.took/]
163+
80164
==== Pre-Indexed Shape
81165

82166
The Query also supports using a shape which has already been indexed in

0 commit comments

Comments
 (0)