Skip to content

Commit d6acd8e

Browse files
authored
Docs: add clarification about geohash use in geohashgrid agg (#36901)
Adds an example on translating geohashes returned by geohashgrid agg as bucket keys into geo bounding box filters in elasticsearch as well as 3rd party applications. Closes #36413
1 parent 54f53d2 commit d6acd8e

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

docs/reference/aggregations/bucket/geohashgrid-aggregation.asciidoc

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,82 @@ POST /museums/_search?size=0
121121
// CONSOLE
122122
// TEST[continued]
123123

124+
The geohashes returned by the `geohash_grid` aggregation can be also used for zooming in. To zoom into the
125+
first geohash `u17` returned in the previous example, it should be specified as both `top_left` and `bottom_right` corner:
126+
127+
[source,js]
128+
--------------------------------------------------
129+
POST /museums/_search?size=0
130+
{
131+
"aggregations" : {
132+
"zoomed-in" : {
133+
"filter" : {
134+
"geo_bounding_box" : {
135+
"location" : {
136+
"top_left" : "u17",
137+
"bottom_right" : "u17"
138+
}
139+
}
140+
},
141+
"aggregations":{
142+
"zoom1":{
143+
"geohash_grid" : {
144+
"field": "location",
145+
"precision": 8
146+
}
147+
}
148+
}
149+
}
150+
}
151+
}
152+
--------------------------------------------------
153+
// CONSOLE
154+
// TEST[continued]
155+
156+
[source,js]
157+
--------------------------------------------------
158+
{
159+
...
160+
"aggregations" : {
161+
"zoomed-in" : {
162+
"doc_count" : 3,
163+
"zoom1" : {
164+
"buckets" : [
165+
{
166+
"key" : "u173zy3j",
167+
"doc_count" : 1
168+
},
169+
{
170+
"key" : "u173zvfz",
171+
"doc_count" : 1
172+
},
173+
{
174+
"key" : "u173zt90",
175+
"doc_count" : 1
176+
}
177+
]
178+
}
179+
}
180+
}
181+
}
182+
--------------------------------------------------
183+
// TESTRESPONSE[s/\.\.\./"took": $body.took,"_shards": $body._shards,"hits":$body.hits,"timed_out":false,/]
184+
185+
For "zooming in" on the system that don't support geohashes, the bucket keys should be translated into bounding boxes using
186+
one of available geohash libraries. For example, for javascript the https://github.com/sunng87/node-geohash[node-geohash] library
187+
can be used:
188+
189+
[source,js]
190+
--------------------------------------------------
191+
var geohash = require('ngeohash');
192+
193+
// bbox will contain [ 52.03125, 4.21875, 53.4375, 5.625 ]
194+
// [ minlat, minlon, maxlat, maxlon]
195+
var bbox = geohash.decode_bbox('u17');
196+
--------------------------------------------------
197+
// NOTCONSOLE
198+
199+
124200
==== Cell dimensions at the equator
125201
The table below shows the metric dimensions for cells covered by various string lengths of geohash.
126202
Cell dimensions vary with latitude and so the table is for the worst-case scenario at the equator.

0 commit comments

Comments
 (0)