# Filling the holes

**URL:** <https://discuss.elastic.co/t/filling-the-holes/19342>\
**Category:** Elasticsearch\
**Created:** [August 19, 2014, 3:08pm UTC](https://discuss.elastic.co/t/filling-the-holes/19342 "2014-08-19T15:08:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aleks](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@Aleks](https://discuss.elastic.co/u/Aleks)\
**Post date:** [August 19, 2014, 3:08pm UTC](https://discuss.elastic.co/t/filling-the-holes/19342/1 "2014-08-19T15:08:37Z")

</div>

Hi there,

I'm currently working with ElasticSearch to make a report that will show  
stocks variable on an e-commerce web site.  
Every minutes, I get products stocks informations (available, sold, initial  
stock) that has changed during the last minute.

Here is an example of two products P1 and P2 with the available stock  
evolution and the aggregation expected VS what I get :

ES result | 30 20 10 15  
expected | 30 20 18 15  
P1 | 10 8 6  
P2 | 20 12 10 9  
h h+1 h+2 h+3

Is is possible to fill the holes with the last (top) result in an  
aggregation ?

Here is my mapping :

{  
"stock": {  
"properties": {  
"OperationID": {  
"type": "long"  
},  
"ProductID": {  
"type": "long"  
},  
"StockEvolution": {  
"type": "nested",  
"properties": {  
"Date": {  
"type": "date",  
"format": "dateOptionalTime"  
},  
"Initial": {  
"type": "long"  
},  
"Real": {  
"type": "long"  
},  
"Sold": {  
"type": "long"  
}  
}  
}  
}  
}  
}

And here is a ES request I'm using :

{  
"size": 0,  
"query": {  
"term": {  
"OperationID": "$1"  
}  
},  
"aggs": {  
"stock\_by\_date": {  
"nested": {  
"path": "StockEvolution"  
},  
"aggs": {  
"stocks": {  
"terms": {  
"field": "StockEvolution.Date",  
"size" : 0,  
"order" : { "\_term" : "asc" }  
},  
"aggs": {  
"sum\_initial": {  
"sum": {  
"field": "StockEvolution.Initial"  
}  
},  
"sum\_real": {  
"sum": {  
"field": "StockEvolution.Real"  
}  
},  
"sum\_sold": {  
"sum": {  
"field": "StockEvolution.Sold"  
}  
}  
}  
}  
}  
}  
}  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/122861ad-5928-4cdd-9825-297e923a0162%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/122861ad-5928-4cdd-9825-297e923a0162%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 1:07am UTC](https://discuss.elastic.co/t/filling-the-holes/19342/2 "2017-07-06T01:07:43Z")

</div>


