【发布时间】:2018-03-13 22:06:41
【问题描述】:
有没有办法在 geo_point 字段上进行聚合并接收实际的经度? 我所能做的就是获取哈希地理。 到目前为止我做了什么: 创建索引
PUT geo_test
{
"mappings": {
"sharon_test": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
}
添加具有不同纬度的 X 文档
POST geo_test/sharon_test
{
"location": {
"lat": 45,
"lon": -7
}
}
运行这个 agg:
GET geo_test/sharon_test/_search
{
"query": {
"bool": {
"must": [
{
"match_all": {}
}
]
}
},
"aggs": {
"locationsAgg": {
"geohash_grid": {
"field": "location",
"precision" : 12
}
}
}
}
我得到了这个结果:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "geo_test",
"_type": "sharon_test",
"_id": "fGb4uGEBfEDTRjcEmr6i",
"_score": 1,
"_source": {
"location": {
"lat": 41.12,
"lon": -71.34
}
}
},
{
"_index": "geo_test",
"_type": "sharon_test",
"_id": "oWb4uGEBfEDTRjcE7b6R",
"_score": 1,
"_source": {
"location": {
"lat": 4,
"lon": -7
}
}
}
]
},
"aggregations": {
"locationsAgg": {
"buckets": [
{
"key": "ebenb8nv8nj9",
"doc_count": 1
},
{
"key": "drm3btev3e86",
"doc_count": 1
}
]
}
}
}
我想知道我是否可以得到以下两个之一: 1. 将当前表示为地理点哈希的“密钥”转换为源 lat/long 2.首先显示聚合中的经纬度
谢谢! 附言 我还尝试了其他地理聚合,但它们给我的只是符合我的 aggs 条件的文档数量,我需要实际值 例如 希望这个聚合返回我在索引中的所有位置,但它只返回计数
GET geo_test/sharon_test/_search
{
"query": {
"bool": {
"must": [
{
"match_all": {}
}
]
}
},
"aggs": {
"distanceRanges": {
"geo_distance": {
"field": "location",
"origin": "50.0338, 36.2242 ",
"unit": "meters",
"ranges": [
{
"key": "All Locations",
"from": 1
}
]
}
}
}
}
【问题讨论】:
标签: elasticsearch