正在使用Elasticsearch 6.4。
我的索引中充满了带有group_id
的文档。
我想按group_id
分组,然后在每个组内按active
的布尔值进行汇总。如果该组中的任何文档处于活动状态,我想返回true。 (我认为我可以使用max
聚合来完成此操作,因为布尔值active
在每个文档中返回1表示true,0表示false。
然后我要对“活动”的组进行计数。
所以,到最后,我只想要一个整数。好吧,将来,我将对其他一些布尔值重复该过程。
这是我尝试过的:
{
"query": {
"bool": {
"must": [
{
"terms": {
"my_filter_terms": [
"foo",
"bar"
]
}
}
]
}
},
"_source": {
"includes": [],
"excludes": []
},
"aggregations": {
"group_by_group_id": {
"terms": {
"field": "group_id",
"size": 10000,
"min_doc_count": 1
},
"aggregations": {
"group_active": {
"max": {
"field": "active"
}
},
"count_total": {
"filters": {
"filters": {
"total": {
"exists": {
"field": "group_id"
}
},
"active": {
"term": {
"group_active": true
}
}
}
}
}
}
}
}
}