【发布时间】:2018-12-13 21:56:27
【问题描述】:
让我们调用我的根级别foo 和我的子级别events。我想在events 级别上进行聚合,但使用过滤器,event 的颜色为“橙色”,或者父级foo 的 customerId 为“35”。
所以,我想在嵌套聚合中创建一个过滤聚合。在这个过滤器的查询子句中,我有一个孩子引用foo 上的一个字段,另一个引用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" }
}
}
}
}
}
}
}
当然,这不起作用,因为包含customer_id 的should 子句的子句不起作用。该术语查询始终为 false,因为在嵌套聚合中无法访问 customer_id。
提前致谢!
【问题讨论】:
标签: elasticsearch elastic-stack elassandra