警告:此功能是实验性的,可能会在未来的版本中完全更改或删除。Elastic将采取最大的努力来解决任何的问题,但是实验功能不受SLA官方功能的支持。
父级管道聚合,计算父级直方图(或日期直方图)聚合中指定度量的累积和。指定的度量必须是数字,并且闭合min_doc_count直方图必须设置为0(默认为histogram聚合)。
{
"cumulative_sum": {
"buckets_path": "the_sum"
}
}
POST /sales/_search
{
"size": 0,
"aggs" : {
"sales_per_month" : {
"date_histogram" : {
"field" : "date",
"interval" : "month"
},
"aggs": {
"sales": {
"sum": {
"field": "price"
}
},
"cumulative_sales": {
"cumulative_sum": {
"buckets_path": "sales" #1
}
}
}
}
}
}
{
"took": 11,
"timed_out": false,
"_shards": ...,
"hits": ...,
"aggregations": {
"sales_per_month": {
"buckets": [
{
"key_as_string": "2015/01/01 00:00:00",
"key": 1420070400000,
"doc_count": 3,
"sales": {
"value": 550.0
},
"cumulative_sales": {
"value": 550.0
}
},
{
"key_as_string": "2015/02/01 00:00:00",
"key": 1422748800000,
"doc_count": 2,
"sales": {
"value": 60.0
},
"cumulative_sales": {
"value": 610.0
}
},
{
"key_as_string": "2015/03/01 00:00:00",
"key": 1425168000000,
"doc_count": 2,
"sales": {
"value": 375.0
},
"cumulative_sales": {
"value": 985.0
}
}
]
}
}
}