【问题标题】:use max/min aggregation on a geo_point field type在 geo_point 字段类型上使用最大/最小聚合
【发布时间】:2017-10-21 01:03:28
【问题描述】:

是否可以在 geo_point 字段上使用最大或最小聚合?

我尝试将max 直接添加到我的坐标属性上,该属性的类型为geo_point

{
    "size": 0,
    "aggs" : {
        "max_lat" : { "max" : { "field" : "coordinate" } }
    }
}

这可以理解地返回一个ClassCastException,因此我尝试直接在coordinatelatlon 字段上运行查询,它们是double 类型。

{
    "size": 0,
    "aggs" : {
        "max_lat" : { "max" : { "field" : "coordinate.lat" } },
        "max_lon" : { "max" : { "field" : "coordinate.lon" } }
    }
}

现在我没有收到 ClassCastExcxeption 并且查询返回 200 但是聚合为空。

回复:

{
    "aggregations": {
        "max_lat": {
            "value": null
        },
        "max_lon": {
            "value": null
        }
    }
}

使用elasticsearch v1.7

【问题讨论】:

    标签: elasticsearch aggregation


    【解决方案1】:

    您可以使用以下脚本聚合:

    {
      "size": 0,
      "aggs": {
        "min_lat": { "min": { "script": "doc['coordinate'].lat" } },
        "max_lat": { "max": { "script": "doc['coordinate'].lat" } },
        "min_lon": { "min": { "script": "doc['coordinate'].lon" } },
        "max_lon": { "max": { "script": "doc['coordinate'].lon" } }
      }
    }
    

    我不确定您是如何使用结果的,但以下内容也可能有助于避免使用脚本:

    "viewport": { "geo_bounds": { "field": "coordinate" } }
    "centroid": { "geo_centroid": { "field": "coordinate" } }
    

    【讨论】:

      猜你喜欢
      • 2015-09-25
      • 2016-11-28
      • 2014-02-22
      • 2014-12-06
      • 2020-12-07
      • 1970-01-01
      • 2016-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多