I need to create a cumulative Average and i have created a following bucket script
i wanted to display total percentage values in Kibana dashboard
GET metricsreport2.0/report/_search
{
"query":{
"match_all": {}
},
"size": 0,
"aggs" : {
"Defects_per_month" : {
"date_histogram" : {
"field" : "Go-LiveDate",
"interval" : "month"
},
"aggs":{
"sales": {
"sum": {
"field": "DefectDensity"
}
},
"totalsum": {
"cumulative_sum": {
"buckets_path": "sales"
}
},
"totalcount": {
"value_count" : { "field" : "DefectDensity" }
},
"totalsumcount": {
"cumulative_sum": {
"buckets_path": "totalcount"
}
} ,
"totalpercentage": {
"bucket_script": {
"buckets_path": {
"totalcumulativesum": "totalsum",
"totalcumulativesum": "totalsumcount"
},
"script": "params.totalcumulativesum/ params.totalcumulativesum"
}
}
}
}
}
}
and the response as follows
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 52,
"max_score": 0,
"hits": []
},
"aggregations": {
"Defects_per_month": {
"buckets": [
{
"key_as_string": "2017-02-01T00:00:00.000Z",
"key": 1485907200000,
"doc_count": 1,
"totalcount": {
"value": 1
},
"sales": {
"value": 23.809524536132812
},
"totalsum": {
"value": 23.809524536132812
},
"totalsumcount": {
"value": 1
},
"totalpercentage": {
"value": 23.809524536132812
}
},
{
"key_as_string": "2017-03-01T00:00:00.000Z",
"key": 1488326400000,
"doc_count": 12,
"totalcount": {
"value": 12
},
"sales": {
"value": 567.7753524780273
},
"totalsum": {
"value": 591.5848770141602
},
"totalsumcount": {
"value": 13
},
"totalpercentage": {
"value": 45.50652900108924
}
},
{
"key_as_string": "2017-04-01T00:00:00.000Z",
"key": 1491004800000,
"doc_count": 4,
"totalcount": {
"value": 4
},
"sales": {
"value": 265.74769401550293
},
"totalsum": {
"value": 857.3325710296631
},
"totalsumcount": {
"value": 17
},
"totalpercentage": {
"value": 50.43132770762724
}
},
{
"key_as_string": "2017-05-01T00:00:00.000Z",
"key": 1493596800000,
"doc_count": 8,
"totalcount": {
"value": 8
},
"sales": {
"value": 507.05126571655273
},
"totalsum": {
"value": 1364.3838367462158
},
"totalsumcount": {
"value": 25
},
"totalpercentage": {
"value": 54.575353469848636
}
},
{
"key_as_string": "2017-06-01T00:00:00.000Z",
"key": 1496275200000,
"doc_count": 13,
"totalcount": {
"value": 13
},
"sales": {
"value": 357.329167842865
},
"totalsum": {
"value": 1721.7130045890808
},
"totalsumcount": {
"value": 38
},
"totalpercentage": {
"value": 45.308236962870545
}
},
{
"key_as_string": "2017-07-01T00:00:00.000Z",
"key": 1498867200000,
"doc_count": 5,
"totalcount": {
"value": 5
},
"sales": {
"value": 0
},
"totalsum": {
"value": 1721.7130045890808
},
"totalsumcount": {
"value": 43
},
"totalpercentage": {
"value": 40.039837316025135
}
}
]
}
}
}