1
我在ES映射中有一個父子關係,我想通過子集上的聚合值(平均值)來篩選父項。也就是說,我只想檢索那些價值在給定範圍內的父母。在Elasticsearch中通過子集聚合篩選父項
我試圖用aggs和後置過濾器來做,但無法讓它工作。
{
"apartments" : {
"mappings" : {
"apartment_availability" : {
"_parent" : {
"type" : "apartment"
},
"_routing" : {
"required" : true
},
"properties" : {
"availability_date" : {
"type" : "date"
},
"apartment_id" : {
"type" : "long"
},
"id" : {
"type" : "long"
},
"price_cents" : {
"type" : "long"
},
"status" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
},
"apartment" : {
"properties" : {
"id" : {
"type" : "long"
},
}
}
}
}
}
如果奧魯用戶選擇期間3月24日至3月31日和€150 - 300€價格區間,那麼我們想向他們展示,在這期間是免費的,所有公寓,其平均價格爲期間在€150-€300範圍內。
下面是我們到目前爲止有:
{
"query": {
"bool": {
"filter": {
"bool": {
"must": [{
"has_child": {
"type": "apartment_availability",
"min_children": 8,
"max_children": 8,
"query": {
"bool": {
"must": [{
"term": {
"status": "available"
}
}, {
"range": {
"availability_date": {
"gte": "2017-03-24",
"lte": "2017-03-31"
}
}
}]
}
}
}
}]
}
}
}
}
}