我存储用户与created字段(索引为日期),我想检索他们的计数与一些日期相关,并汇总它按天为上个月。想象一下,网站上每隔一天就会有新的注册--所以我想要得到这样的东西:
date count
2017-02-01 10
2017-02-02 10
2017-02-03 11
2017-02-04 11
2017-02-05 12
2017-02-06 12
2017-02-07 13
2017-02-08 13
2017-02-09 14
2017-02-10 14
2017-02-11 15
...有什么方法可以做到这一点吗?
发布于 2017-02-11 21:36:13
以Date Histogram Aggregation为例:
{
"aggs" : {
"registrations_over_time" : {
"date_histogram" : {
"field" : "created",
"interval" : "day"
}
}
}
}发布于 2017-02-12 21:15:19
date_histogram很有帮助,但每天只返回“新用户”。要获得特定日期的总用户数,我必须添加如下内容:
{
"aggs": {
"users": {
"date_histogram": {
"field": "created",
"interval": "day",
"format": "yyyy-MM-dd"
},
"aggs": {
"users_stats": {
"stats": {
"field": "id"
}
},
"cumulative_users": {
"cumulative_sum": {
"buckets_path": "users_stats.count"
}
}
}
}
}
}https://stackoverflow.com/questions/42175992
复制相似问题