在 geo_point 字段类型上使用 max/min 聚合

use max/min aggregation on a geo_point field type

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

我试过 max 直接到我的坐标 属性 上,它的类型是 geo_point

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

这是可以理解的 returns ClassCastException 所以我尝试 运行 直接在 [=20= 的 latlon 字段上查询] 类型为 double.

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

现在我没有收到 ClassCastExcxeption 和查询 returns a 200,但是聚合为空。

回复:

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

使用 elasticsearch v1.7

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

{
  "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" } }