# How to combine several histograms?

**URL:** <https://discuss.elastic.co/t/how-to-combine-several-histograms/84128>\
**Category:** Elasticsearch\
**Created:** [May 1, 2017, 4:52am UTC](https://discuss.elastic.co/t/how-to-combine-several-histograms/84128 "2017-05-01T04:52:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ailinykh](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@ailinykh](https://discuss.elastic.co/u/ailinykh)\
**Post date:** [May 1, 2017, 4:52am UTC](https://discuss.elastic.co/t/how-to-combine-several-histograms/84128/1 "2017-05-01T04:52:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 29, 2017, 5:04am UTC](https://discuss.elastic.co/t/how-to-combine-several-histograms/84128/2 "2017-05-29T05:04:26Z")

</div>

Closed on May 29, 2017, 5:04am UTC

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