【问题标题】:Aggregation on geo_piont elasticsearchgeo_piont elasticsearch上的聚合
【发布时间】: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


    【解决方案1】:

    您实际上可以在 geo_hash 中使用 geo_bounds 来获取边界框以精确缩小范围,但要获得您需要解码 geohash 的确切位置

    GET geo_test/sharon_test/_search
    {
       "query":{
          "bool":{
             "must":[
                {
                   "match_all":{
    
                   }
                }
             ]
          }
       },
       "aggs":{
          "locationsAgg":{
             "geohash_grid":{
                "field":"location",
                "precision":12
             },
             "aggs":{
                "cell":{
                   "geo_bounds":{
                      "field":"location"
                   }
                }
             }
          }
       }
    }
    

    【讨论】:

    • 是的,您必须使用第三方库并在客户端进行后期处理。在您的情况下,12 的精度基本上是一平方米,所以应该足够了
    • 我的意思是你可以。
    猜你喜欢
    • 2014-06-17
    • 1970-01-01
    • 2017-09-24
    • 2017-01-06
    • 2014-11-18
    • 1970-01-01
    • 2018-01-12
    • 2023-04-03
    • 1970-01-01
    相关资源
    最近更新 更多