悟空,拿我的打狗棒来

elasticsearch 前缀(模糊) 聚合

Elasticsearch | 作者 liulei | 发布于2018年01月04日 | 阅读数:3368


有以下数据,如何统计 statuscode 中 400(403,404 看做400)和 500(503,505 看做500)的数量?
能用聚合实现最好,不能用聚合其他方式只要能得到预期结果就行。
求大佬们不吝赐教。
[
{
"statuscode": "200",
"method": "GET",
"reqtime": 4265,
"url": "http://www.baidu.com/news/2017 ... ot%3B
},
{
"statuscode": "400",
"method": "GET",
"reqtime": 29009,
"url": "http://www.baidu.com/news/2017 ... ot%3B
},
{
"statuscode": "404",
"method": "get",
"reqtime": 3632,
"url": "http://www.baidu.com/"
},
{
"statuscode": "403",
"method": "GET",
"reqtime": 4560,
"url": "http://www.baidu.com/news/2017 ... ot%3B
},
{
"statuscode": "200",
"method": "GET",
"reqtime": 9217,
"url": "http://www.baidu.com/news/2017 ... ot%3B
},
{
"statuscode": "503",
"method": "GET",
"reqtime": 3237,
"url": "http://www.baidu.com/news/2017 ... ot%3B
},
{
"statuscode": "505",
"method": "GET",
"reqtime": 29687,
"url": "http://www.baidu.com/news/2017 ... ot%3B
},
{
"statuscode": "500",
"method": "GET",
"reqtime": 39081,
"url": "http://www.baidu.com/news/2017 ... ot%3B
},
{
"statuscode": "200",
"method": "GET",
"reqtime": 11015,
"url": "http://www.baidu.com/news/2017 ... ot%3B
},
{
"statuscode": "200",
"method": "GET",
"reqtime": 11653,
"url": "http://www.baidu.com/news/2017 ... ot%3B
}
]

]
已邀请:

strglee

赞同来自: liulei

正好直方图聚合可以满足你的需求
 
{
"aggs" : {
"statuscode" : {
"histogram" : {
"field" : "statuscode",
"interval" : 100
}
}
}
}

要回复问题请先登录注册