[英]How to calculate average using aggregated values in elasticsearch?
如果這是文件的一小部分,
{ "metricName" : "call", "createdDate" : "2019-10-31T00:00:00.000Z", "responseCode: "200" }
{ "metricName" : "email", "createdDate" : "2019-10-31T00:00:00.000Z", "responseCode: "400" }
{ "metricName" : "chat", "createdDate" : "2019-10-31T00:00:00.000Z", "responseCode: "300" }
.
.
我需要在一個查詢中執行以下操作。
聚合 API 允許使用子聚合按多個字段進行分組。 假設您要按字段 field1、field2 和 field3 進行分組:
您的 1,2 和 3 問題已通過此查詢解決。
POST /stackoverflow/_search?size=0
{
"query": {
"bool": {
"must": [
{
"match_phrase": {
"createdDate": {
"query": "2019-10-31T00:00:00.000Z",
"slop": 0,
"zero_terms_query": "NONE",
"boost": 1
}
}
},
{
"match_phrase": {
"responseCode": {
"query": "200",
"slop": 0,
"zero_terms_query": "NONE",
"boost": 1
}
}
},
{
"match_phrase": {
"metricName": {
"query": "call",
"slop": 0,
"zero_terms_query": "NONE",
"boost": 1
}
}
}
]
}
},
"aggr": {
"agg1": {
"terms": {
"field": "metricName",
"size": 10,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
}
},
"aggs": {
"agg2": {
"terms": {
"field": "createdDate",
"size": 10,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.