让我们称我的根级别foo
和我的子级别events
。我想在级别上进行聚合,但使用具有颜色“橙色”或父级具有 customerId“35”events
的过滤器。event
foo
所以,我想要一个嵌套聚合内的过滤聚合。在这个过滤器的查询子句中,我有一个孩子指的是一个字段 onfoo
而另一个指的是一个字段 on events
。但是,第一个孩子无法像那样实际引用父母!我不能使用 reverse_nested 聚合,因为我不能将其中一个作为复合查询的子级,并且我不能在嵌套之前进行过滤,因为那样我会失去 OR 语义。如何引用该字段foo
?
如果有帮助,请举个具体的例子。映射:
{
"foo": {
"properties": {
"customer_id": { "type": "long" },
"events": {
"type": "nested",
"properties": {
"color": { "type": "keyword" },
"coord_y": { "type": "double" }
}
}
}
}
}
foo
(为清楚起见更新:这是一个以根映射命名的索引foo
)
我希望能够进行的查询:
{
"aggs": {
"OP0_nest": {
"nested": { "path": "events" },
"aggs": {
"OP0_custom_filter": {
"filter": {
"bool": {
"should": [
{ "term": { "events.color": "orange" } },
{ "term": { "customer_id": 35 } }
]
}
},
"aggs": {
"OP0_op": {
"avg": { "field": "events.coord_y" }
}
}
}
}
}
}
}
当然,这不起作用,因为should
包含子句的子句customer_id
不起作用。该术语查询始终为假,因为customer_id
无法在嵌套聚合中访问。
提前致谢!