How to combine several histograms?

Hello everybody!
I have data points like this
{
"timestamp": 12345
"value": 12.3
"source": "s1"
}

roughly speaking this is a bunch of time series coming from different sources. My goal is to select data from any number of sources and sum them up. So, for sources s1, s4, s23 I should build time series
{
"timestamp": 12345
"value": s1.value + s4.value + s23.value
}

Unfortunately, I can't use simple bucket aggregation, because some points could be missed and I have to fill gap with pervious value. So, my first question is - can I fill gaps in histograms with pervious value?

Also I may want to apply some simple transformation on time series ( just value*value, fro example) and then sum them up. How to do it?
I tried to build nested buckets source/timestamp. Something like this:

"terms": {
"field": "source"
},
"aggs": {
"values": {
"histogram": {
"field": "timestamp",
"interval": 1
},
...

I can modify each histogram, but how to sum them up?

Thank you,
Andrey

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.