我正在努力使用更高级别元素的值过滤嵌套聚合。我已经在下面的代码中应用了提示的位置和操作。
案例是我希望每个路径有一个聚合,因此不应该创建另一个带路径的聚合:' events'尽可能使用角色的内部聚合。
GET _search
{
"filter": {},
"aggs": {
"events.role.name5": {
"filter": {},
"aggs": {
"inner": {
"nested": {
"path": "events.role"
},
"aggs": {
"filtered.aggs": {
"filter": {
// Here I'd have something like:
"terms": {
"events.id": [
448,
435
]
}
// of course that does not work because of context.
},
"aggs": {
"events.role.name": {
"terms": {
"field": "events.role.name",
"size": 50
}
},
"events.role.name_count": {
"cardinality": {
"field": "events.role.name"
}
}
}
}
}
}
}
},
"events.name12": {
"filter": {},
"aggs": {
"inner": {
"nested": {
"path": "events"
},
"aggs": {
"filtered.aggs": {
"filter": {
"terms": {
"events.id": [
448,
435
]
}
},
"aggs": {
"events.name": {
"terms": {
"field": "events.name",
"size": 5
}
},
"events.name_count": {
"cardinality": {
"field": "events.name"
}
}
}
}
}
}
}
}
},
"size": 5,
"_source": [
"events",
"address"
]
}
CASE IS 达到相同的结果不使用:
"aggs": {
"inner": {
"nested": {
"path": "events"
},
"aggs": {
"filtered.aggs": {
"filter": {
"terms": {
"events.id": [
448,
435
]
}
},
"aggs": {
"inner": {
"nested": {
"path": "events.role"
},
"aggs": {
"filtered.aggs": {
"filter": {},
"aggs": {
"events.role.name": {
"terms": {
"field": "events.role.name",
"size": 50
}
},
"events.role.name_count": {
"cardinality": {
"field": "events.role.name"
}
}
}
}
}
}
}
}
}
}
}