【发布时间】:2021-10-08 12:14:23
【问题描述】:
我需要用 geo_bounding_box 构建 geotitle_grid 聚合
这是我的代码:
search_query: DslSearch = DslSearch()
enriched_value = {
"aggregations": {
"AggregationGeotileGridBuckets": {
"geotile_grid": {
"field": "location",
"precision": 8,
"size": 10000
}
}
}
}
bucket_builder = search_query.aggs.bucket(
name='My bucket',
agg_type='filter',
**{
"geo_bounding_box": {
"location": {
"top_left": {
"lat": 38.2715027604674,
"lon": -121.925823154605
},
"bottom_right": {
"lat": 37.2876652395326,
"lon": -122.91285484539499
}
}
}
},
**enriched_value
)
但在 elasticsearch_dsl 库中构建此查询后,我有错误:
elasticsearch.exceptions.RequestError: RequestError(400, 'parsing_exception', '[geo_bounding_box] 格式错误的查询,应为 [END_OBJECT] 但找到 [FIELD_NAME]')
这里是查询。这是构建的:
{
"query": {
"geo_distance": {
"distance": "497668.76297287986m",
"location": {
"lat": 38.99939107394144,
"lon": -124.2156036484375
}
}
},
"aggs": {
"AggregationGeotileGrid": {
"filter": {
"geo_bounding_box": {
"location": {
"top_left": {
"lat": 38.2715027604674,
"lon": -121.925823154605
},
"bottom_right": {
"lat": 37.2876652395326,
"lon": -122.91285484539499
}
}
},
"aggregations": {
"AggregationGeotileGridBuckets": {
"geotile_grid": {
"field": "location",
"precision": 8,
"size": 10000
}
}
}
}
}
},
"size": 0
}
如何使用边界框过滤器构建写入聚合查询以及我在哪里出错? 将不胜感激。
【问题讨论】:
标签: python elasticsearch elasticsearch-aggregation elasticsearch-dsl-py