Den*_*Ich 2 search search-engine elasticsearch
我想用形状和边界框按位置对数据进行分组。例如按半球对结果进行分组:
GET cdc/_search
{
"from": 0,
"size": 0,
"query": {
"match_all": {}
},
"aggs": {
"group_by_geo": {
"geo_bounding_box": {
"field": "location",
"boxes": [
{
"top_left": {
"lat": 90,
"lon": -180
},
"bottom_right": {
"lat": 0,
"lon": 0
}
},
{
"top_left": {
"lat": 90,
"lon": 0
},
"bottom_right": {
"lat": 0,
"lon": 180
}
},
{
"top_left": {
"lat": 0,
"lon": -180
},
"bottom_right": {
"lat": -90,
"lon": 0
}
},
{
"top_left": {
"lat": 0,
"lon": 0
},
"bottom_right": {
"lat": -90,
"lon": 180
}
}
]
},
"aggs": {
"over_time": {
"date_histogram": {
"field": "date",
"interval": "day",
"format": "yyyy-MM-dd"
},
"aggs": {
"AvgTemp": {
"avg": {
"field": "hits"
}
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
所以这over_time部分工作得很好,但这个查询给了我"reason": "Could not find aggregator type [geo_bounding_box] in [group_by_geo]"
我的语法受到范围聚合的启发,但显然这在这种情况下不起作用。
这是可能的还是我必须通过 4 个框进行单独的查询过滤?
没有geo_bounding_box聚合,(不过有一个geo_bounding_box过滤器)。
您可以使用filters包含每个边界框一个geo_bounding_box过滤器的聚合来实现您需要的功能。基本上是这样的:
{
"from": 0,
"size": 0,
"query": {
"match_all": {}
},
"aggs": {
"group_by_geo": {
"filters": {
"filters": {
"box1": {
"geo_bounding_box": {
"location": {
"top_left": {
"lat": 90,
"lon": -180
},
"bottom_right": {
"lat": 0,
"lon": 0
}
}
}
},
"box2": {
"geo_bounding_box": {
"location": {
"top_left": {
"lat": 90,
"lon": 0
},
"bottom_right": {
"lat": 0,
"lon": 180
}
}
}
},
"box3": {
"geo_bounding_box": {
"location": {
"top_left": {
"lat": 0,
"lon": -180
},
"bottom_right": {
"lat": -90,
"lon": 0
}
}
}
},
"box4": {
"geo_bounding_box": {
"location": {
"top_left": {
"lat": 0,
"lon": 0
},
"bottom_right": {
"lat": -90,
"lon": 180
}
}
}
}
}
},
"aggs": {
"over_time": {
"date_histogram": {
"field": "date",
"interval": "day",
"format": "yyyy-MM-dd"
},
"aggs": {
"AvgTemp": {
"avg": {
"field": "hits"
}
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
183 次 |
| 最近记录: |