2017-10-20 223 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" } }