Last active
November 8, 2016 18:59
-
-
Save eskibars/4bb247d69e45a3bc8daa439b35e6cf89 to your computer and use it in GitHub Desktop.
Cumulative sum + serial differencing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
POST t/type_name | |
{ | |
"d": "2016-01-01T01:01:01", | |
"foo": 1 | |
} | |
POST t/type_name | |
{ | |
"d": "2016-01-02T01:01:01", | |
"foo": 2 | |
} | |
POST t/type_name | |
{ | |
"d": "2016-01-03T01:01:01", | |
"foo": 3 | |
} | |
POST t/type_name | |
{ | |
"d": "2016-01-04T01:01:01", | |
"foo": 4 | |
} | |
POST t/type_name | |
{ | |
"d": "2016-01-05T01:01:01", | |
"foo": 5 | |
} | |
POST t/type_name | |
{ | |
"d": "2016-01-06T01:01:01", | |
"foo": 6 | |
} | |
GET t/_search | |
{ | |
"query": { | |
"match_all": {} | |
}, | |
"aggs": { | |
"hist": { | |
"date_histogram" : { | |
"field" : "d", | |
"interval" : "day" | |
}, | |
"aggs": { | |
"v": { | |
"sum": { | |
"field": "foo" | |
} | |
}, | |
"sum_foo": { | |
"cumulative_sum": { | |
"buckets_path": "v" | |
} | |
}, | |
"diff": { | |
"serial_diff": { | |
"buckets_path": "sum_foo", | |
"lag": 2 | |
} | |
} | |
} | |
} | |
}, | |
"size": 0 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"took": 7, | |
"timed_out": false, | |
"_shards": { | |
"total": 5, | |
"successful": 5, | |
"failed": 0 | |
}, | |
"hits": { | |
"total": 6, | |
"max_score": 0, | |
"hits": [] | |
}, | |
"aggregations": { | |
"hist": { | |
"buckets": [ | |
{ | |
"key_as_string": "2016-01-01T00:00:00.000Z", | |
"key": 1451606400000, | |
"doc_count": 1, | |
"v": { | |
"value": 1 | |
}, | |
"sum_foo": { | |
"value": 1 | |
} | |
}, | |
{ | |
"key_as_string": "2016-01-02T00:00:00.000Z", | |
"key": 1451692800000, | |
"doc_count": 1, | |
"v": { | |
"value": 2 | |
}, | |
"sum_foo": { | |
"value": 3 | |
} | |
}, | |
{ | |
"key_as_string": "2016-01-03T00:00:00.000Z", | |
"key": 1451779200000, | |
"doc_count": 1, | |
"v": { | |
"value": 3 | |
}, | |
"sum_foo": { | |
"value": 6 | |
}, | |
"diff": { | |
"value": 5 | |
} | |
}, | |
{ | |
"key_as_string": "2016-01-04T00:00:00.000Z", | |
"key": 1451865600000, | |
"doc_count": 1, | |
"v": { | |
"value": 4 | |
}, | |
"sum_foo": { | |
"value": 10 | |
}, | |
"diff": { | |
"value": 7 | |
} | |
}, | |
{ | |
"key_as_string": "2016-01-05T00:00:00.000Z", | |
"key": 1451952000000, | |
"doc_count": 1, | |
"v": { | |
"value": 5 | |
}, | |
"sum_foo": { | |
"value": 15 | |
}, | |
"diff": { | |
"value": 9 | |
} | |
}, | |
{ | |
"key_as_string": "2016-01-06T00:00:00.000Z", | |
"key": 1452038400000, | |
"doc_count": 1, | |
"v": { | |
"value": 6 | |
}, | |
"sum_foo": { | |
"value": 21 | |
}, | |
"diff": { | |
"value": 11 | |
} | |
} | |
] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment