[英]Aggregate by two or more fields in elasticsearch
I have many documents with various ProcessName
. 我有许多带有各种
ProcessName
文档。 Each has some status code named Code
. 每个都有一些名为
Code
状态代码。
I need to aggregate the documents by those two fields. 我需要按这两个字段汇总文档。
For instance: 例如:
ProcessA
code: 1
count: 220
ProcessA
code: 2
count: 335
ProcessB
code: 2
count: 520
ProcessC
code: 3
count: 520
I've managed to aggregate only by one field ( ProcessName
): 我设法只按一个字段(
ProcessName
)进行汇总:
POST /_search
{
"query": {
"bool": {
"must": [
{
"term": {
"_type": "monitor"
}
}
]
}
},
"aggs" : {
"ProcessNameAgg" : {
"terms" : { "field" : "ProcessName",
"size" : 5,
"order" : { "_count" : "desc" }
}
}
}
}
I've tried to make terms
an array with two fields, but unfortunately I'm getting parsing exception (terms should get ONLY one field). 我试图使
terms
成为具有两个字段的数组,但是不幸的是,我正在解析异常(terms应该只有一个字段)。
Try this: 尝试这个:
POST /_search
{
"query": {
"bool": {
"must": [
{
"term": {
"_type": "monitor"
}
}
]
}
},
"aggs": {
"ProcessNameAgg": {
"terms": {
"field": "ProcessName",
"size": 5,
"order": {
"_count": "desc"
}
},
"aggs": {
"codes": {
"terms": {
"field": "code",
"size": 10
}
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.