2017-02-11 23 views
0

我存储的用户与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 
... 

有什么办法来实现这一目标?

回答

0

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" 
        } 
       } 
      } 
     } 
    } 
}