即使是不成熟的尝试,也胜于胎死腹中的策略。

对索引进行agg terms统计后,如何对查询出来的数据根据doc_count进行范围内统计呢?

Elasticsearch | 作者 对你无可奈何 | 发布于2018年04月17日 | 阅读数:4118


elk.png


和客户端约定了 每分钟会发过来一条信息,对应user的doc_count条数是用户的在线时长。user具有唯一性,想设置一个范围,比如doc_count:120-480的范围进行用户数量的统计,该怎么搞呢...
已邀请:

laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net

赞同来自:

GET time_index/_search
{
"size":0,
"aggs":{
"time_histogram" : {
"histogram":{
"field": "time_long",
"interval": 100
}
}
}
}

{
"took": 64,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 9,
"max_score": 0,
"hits": []
},
"aggregations": {
"time_histogram": {
"buckets": [
{
"key": 100,
"doc_count": 4
},
{
"key": 200,
"doc_count": 3
},
{
"key": 300,
"doc_count": 2
}
]
}
}
}

windyyong - zjy

赞同来自:

请问楼主实现了该方式吗

对你无可奈何

赞同来自:

我的不是这样的呢,我的doc_count是时长,key其实是用户的id呢....有什么办法把doc_count做成一个范围呢,然后统计下此范围内有多少用户呢,因为用户的时间不是直接写过来的,是每分钟会发一条过来,所以我的doc_count是时长呢,求大神指导下呢

要回复问题请先登录注册