在elasticsearch中使用geohash_grid aggs返回此结果:
"aggregations": {
"Geo-hash": {
"buckets": [
{
"key": "gcw05r6xz7cb",
"doc_count": 305
},
{
"key": "gcw2hzkpf7b8",
"doc_count": 12
}
]
}
}
1)键代表单元格的中心点?
2)如何将此密钥转换为lat lon? - 我发现有些插件可以避免使用插件(不支持所有版本,需要维护等)并直接从elasticsearch查询地理字体?
答案 0 :(得分:1)
回答你的问题:
键中的地理位置代表一个区域。有关geohashes的更多详细信息,请阅读此内容: https://www.elastic.co/guide/en/elasticsearch/guide/current/geohashes.html
从本弹性搜索文档的最后一节有关geohash网格聚合的内容,您需要一个库将geohash转换为等效的边界框或中心点。 https://www.elastic.co/guide/en/elasticsearch/guide/current/geohash-grid-agg.html#geohash-grid-agg
您可以探索Geo Bounds Aggregation来执行类似的工作,但我更喜欢在客户端进行转换。
答案 1 :(得分:1)
我在问题中描述的唯一方法是在网络上使用众多插件中的一个,as this one
无论如何,如果您的数据集和基数不是太大,您可以使用热门aggs作为子aggs,然后从文档中提取地理点字段。 这可能是非常昂贵的操作,明智地在小数据集上使用它:)
{
"size": 0,
"aggs": {
"geo": {
"geohash_grid": {
"field": "locationField",
"precision": 3
}
,
"aggs": {
"NAME": {
"top_hits": {
"size": 1
}
}
}
}
}
}