比方说,我有这份文件:
POST bug_reports/_doc/1
{
"title": "Results are not sorted correctly.",
"labels": {
"priority": "urgent",
"product": "A"
}
}
labels
字段是平坦的,这意味着我们不知道键的数量/名称。
如果我得到一个聚合,它会为bucket提供如下所示的内容:
{
"buckets": [
{
"key": "urgent",
"doc_count": 27705
},
{
"key": "no urgent",
"doc_count": 705
}
]
}
这是预期的结果,但我想创建一个聚合,包括键,值和每个键在扁平字段内的doc_count。
{
"buckets": [
{
"key": "priority",
"values": [
{
"key": "urgent",
"doc_count": 27705
},
{
"key": "no urgent",
"doc_count": 705
}
]
},
{
"key": "product",
"values": [
{
"key": "A",
"doc_count": 3215
}
]
}
]
}
这是可能的吗?我已经检查了与composite
和multi_terms
聚合相关的文档,但它们似乎是针对不同的用例。谢谢!
1条答案
按热度按时间jdg4fx2g1#
可以在一个查询中使用多个聚合。例如:
聚合
all fields inside an object automatically
是不可能的,但是可以在聚合之前找到并定义它。答复: