Elasticsearch DSL. Как построить фильтр по geo bounding box внутри агрегации по geotile_grid
Всем привет.
Пытаюсь построить с помощью либы dsl агрегационный запрос с фильтром geo bounding box внутри. Вот пример моего рабочего запроса:
GET my_index/_search?size=0
{
"aggs": {
"geo_bounding_box": {
"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": 5,
"size": 10000
}
}
}
}
}
}
Вот ответ эластика:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 226,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"geo_bounding_box" : {
"doc_count" : 9,
"AggregationGeotileGridBuckets" : {
"buckets" : [
{
"key" : "5/7/12",
"doc_count" : 4
},
{
"key" : "5/5/12",
"doc_count" : 4
},
{
"key" : "5/6/12",
"doc_count" : 1
}
]
}
}
}
}
Пытаюсь сделать идентичный запрос с помощью либы:
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
)
Но получается такой запрос и ошибка:
{
"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
}
Ошибка:
elasticsearch.exceptions.RequestError: RequestError(400, 'parsing_exception', '[geo_bounding_box] malformed query, expected [END_OBJECT] but found [FIELD_NAME]')
Был бы очень благодарен, за подсказку, куда мне смотреть и в общем, правильно ли я построил агрегацию с фильтром с помощью либы.