2017-10-20 76 views
0

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

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

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

这可以理解返回ClassCastException,所以我想直接的coordinatelatlon场运行查询其是双重类型的。

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

回答

0

您可以使用下面的脚本集合:

{ 
    "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" } } 
相关问题