# Aggregation using the results of an aggregation?

**URL:** <https://discuss.elastic.co/t/aggregation-using-the-results-of-an-aggregation/18592>\
**Category:** Elasticsearch\
**Created:** [July 11, 2014, 12:39am UTC](https://discuss.elastic.co/t/aggregation-using-the-results-of-an-aggregation/18592 "2014-07-11T00:39:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greg\_Day](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/greg_day/32/1424_2.png) [@Greg\_Day](https://discuss.elastic.co/u/Greg_Day)\
**Post date:** [July 11, 2014, 12:39am UTC](https://discuss.elastic.co/t/aggregation-using-the-results-of-an-aggregation/18592/1 "2014-07-11T00:39:16Z")

</div>

Hi guys

Im wondering if it is possible to use the results of an aggregation in a  
aggregation calculation?  
eg: How would I calculate stocktosales in the example below?

....  
"aggregations": {  
"product": {  
"aggregations": {  
"sales": {  
"sum": {  
"field": "Sale"  
}  
},  
"onhand": {  
"avg": {  
"field": "Onhand"  
}  
},  
"_stocktosales_" : {  
\* should be onhand/sales\*  
}  
}  
}  
}

Thanks!

Greg

--  
Watch the fun new 2 minute and 2 second video tour of Vend  
[http://youtu.be/zh2X8FyKyMI](http://youtu.be/zh2X8FyKyMI)

--  
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/723d04b4-68b3-4290-92f4-d391a514e48b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/723d04b4-68b3-4290-92f4-d391a514e48b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Remi\_Nonnon](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@Remi\_Nonnon](https://discuss.elastic.co/u/Remi_Nonnon)\
**Post date:** [July 11, 2014, 7:39am UTC](https://discuss.elastic.co/t/aggregation-using-the-results-of-an-aggregation/18592/2 "2014-07-11T07:39:41Z")

</div>

Hi,

If I am not wrong it's not possible yet to use the result of an aggregation  
in another one.  
You have to do that outside elasticsearch.

Regards,  
Rémi

Le vendredi 11 juillet 2014 02:39:16 UTC+2, Greg Day a écrit :

> Hi guys
> 
> Im wondering if it is possible to use the results of an aggregation in a  
> aggregation calculation?  
> eg: How would I calculate stocktosales in the example below?
> 
> ....  
> "aggregations": {  
> "product": {  
> "aggregations": {  
> "sales": {  
> "sum": {  
> "field": "Sale"  
> }  
> },  
> "onhand": {  
> "avg": {  
> "field": "Onhand"  
> }  
> },  
> "_stocktosales_" : {  
> \* should be onhand/sales\*  
> }  
> }  
> }  
> }
> 
> Thanks!
> 
> Greg
> 
> Watch the fun new 2 minute and 2 second video tour of Vend  
> [http://youtu.be/zh2X8FyKyMI](http://youtu.be/zh2X8FyKyMI)

--  
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/0e701b9f-068d-4410-8eaf-51903bc08b2c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0e701b9f-068d-4410-8eaf-51903bc08b2c%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:16am UTC](https://discuss.elastic.co/t/aggregation-using-the-results-of-an-aggregation/18592/3 "2017-07-06T01:16:36Z")

</div>


