Using geohash_grid aggs in elasticsearch return this result:
"aggregations": {
"Geo-hash": {
"buckets": [
{
"key": "gcw05r6xz7cb",
"doc_count": 305
},
{
"key": "gcw2hzkpf7b8",
"doc_count": 12
}
]
}
}
1)The key represent the center point of cell?
2)How to convert this key to lat lon? - I found some plugins is there anyway to avoid using plugins (not support all version , needs maintenance,etc.) and query directly geo ponts from elasticsearch?
To answer your question:
The geohashes in the key represent an area. Please read this for more details about geohashes: https://www.elastic.co/guide/en/elasticsearch/guide/current/geohashes.html
From the last section in this elasticsearch documentation about geohash grid aggregation, you need a library to convert a geohash into the equivalent bounding box or central point. https://www.elastic.co/guide/en/elasticsearch/guide/current/geohash-grid-agg.html#geohash-grid-agg
You may explore Geo Bounds Aggregation to perform similar job, but I prefer convert it at client side.
The only way as i described in my question is to use one of many plugins a cross the web, as this one
Any way if your data-set and cardinality is not too large you can use top hits aggs as sub aggs and then extract the geo-point field from the document. That can be very expensive operation, use it wisely on small data-sets :)
{
"size": 0,
"aggs": {
"geo": {
"geohash_grid": {
"field": "locationField",
"precision": 3
}
,
"aggs": {
"NAME": {
"top_hits": {
"size": 1
}
}
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With