我想求每天日志数量的平均值。我的思路是按照时间进行分组,
{
"size":0,
"aggs":{
"group_by_date":{
"date_histogram": {
"field": "@timestamp",
"interval": "day"
}
}
}
}
这样拿到了doc_count 然后对doc_count 进行求平均值。我在手册上没有找到相关的api。求大神的一个思路。以下是我完整的dsl:
{
"size":0,
"aggs":{
"group_by_date":{
"date_histogram": {
"field": "@timestamp",
"interval": "day"
}
},
"avg_stately_day" : {
"avg_bucket": {
"buckets_path": "group_by_date.doc_count"
}
}
}
}
我的返回结果
"aggregations" : {
"group_by_date" : {
"buckets" : [
{
"key_as_string" : "2020-10-30T00:00:00.000Z",
"key" : 1604016000000,
"doc_count" : 809
},
{
"key_as_string" : "2020-10-31T00:00:00.000Z",
"key" : 1604102400000,
"doc_count" : 166
}
]
},
"avg_stately_day" : {
"value" : null
}}
1 个回复
pony_maggie - 公众号:犀牛饲养员的技术笔记
赞同来自: