# Sub-aggregations: percentiles of sum

**URL:** <https://discuss.elastic.co/t/sub-aggregations-percentiles-of-sum/18012>\
**Category:** Elasticsearch\
**Created:** [June 10, 2014, 9:33am UTC](https://discuss.elastic.co/t/sub-aggregations-percentiles-of-sum/18012 "2014-06-10T09:33:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marek\_Skorek](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Marek\_Skorek](https://discuss.elastic.co/u/Marek_Skorek)\
**Post date:** [June 10, 2014, 9:33am UTC](https://discuss.elastic.co/t/sub-aggregations-percentiles-of-sum/18012/1 "2014-06-10T09:33:26Z")

</div>

Hi,

I have a question about subaggregations.

The case is that I have small documents (single opratations) with duration  
time of this operation which I want to aggregate and finally get the  
percentile of this sum.

Example:  
| operation | time |  
| A | 10 |  
| A | 20 |  
| B | 100 |  
| B | 1000 |  
| C | 10 |  
| C | 10 |

_Request:_  
{  
"aggs": {  
"by\_operation": {  
"terms" : {  
"field" : "operation"  
},  
"aggs" : {  
"sum\_times" : {  
"sum" : { "field" : "time"}  
}  
}  
}  
},  
"size" : 0  
}

_Results:_  
{ ...  
"aggregations": {  
"by\_operation": {  
"buckets": [{  
"key": "a",  
"doc\_count": 2,  
"sum\_times": {  
"value": 30.0  
}  
},  
{  
"key": "c",  
"doc\_count": 2,  
"sum\_times": {  
"value": 20.0  
}  
},  
{  
"key": "b",  
"doc\_count": 2,  
"sum\_times": {  
"value": 1100.0  
}  
}]  
}  
}  
}

After that it will be nice to have i.e. percentile of the field _sum\_times_.  
I know it can be ordered by the "sum\_times" aggregate but it only gives  
some kind of the biggest/smallest times but not percentiles ☹  
_Question:_ Is it possible to take that value from another aggreagation?

Thank you for any answer 🙂

Regards,  
Marek Skorek.

--  
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/c4bc31ad-ca6e-4041-89b2-ae09fb12a2c0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c4bc31ad-ca6e-4041-89b2-ae09fb12a2c0%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [June 11, 2014, 3:01pm UTC](https://discuss.elastic.co/t/sub-aggregations-percentiles-of-sum/18012/2 "2014-06-11T15:01:42Z")

</div>

Hi,

This is a feature that we are considering but it is unfortunately not  
available for the moment.

On Tue, Jun 10, 2014 at 11:33 AM, Marek Skorek [scoropl@gmail.com](mailto:scoropl@gmail.com) wrote:

> Hi,
> 
> I have a question about subaggregations.
> 
> The case is that I have small documents (single opratations) with duration  
> time of this operation which I want to aggregate and finally get the  
> percentile of this sum.
> 
> Example:  
> | operation | time |  
> | A | 10 |  
> | A | 20 |  
> | B | 100 |  
> | B | 1000 |  
> | C | 10 |  
> | C | 10 |
> 
> _Request:_  
> {  
> "aggs": {  
> "by\_operation": {  
> "terms" : {  
> "field" : "operation"  
> },  
> "aggs" : {  
> "sum\_times" : {  
> "sum" : { "field" : "time"}  
> }  
> }  
> }  
> },  
> "size" : 0  
> }
> 
> _Results:_  
> { ...  
> "aggregations": {  
> "by\_operation": {  
> "buckets": [{  
> "key": "a",  
> "doc\_count": 2,  
> "sum\_times": {  
> "value": 30.0  
> }  
> },  
> {  
> "key": "c",  
> "doc\_count": 2,  
> "sum\_times": {  
> "value": 20.0  
> }  
> },  
> {  
> "key": "b",  
> "doc\_count": 2,  
> "sum\_times": {  
> "value": 1100.0  
> }  
> }]  
> }  
> }  
> }
> 
> After that it will be nice to have i.e. percentile of the field  
> _sum\_times_. I know it can be ordered by the "sum\_times" aggregate but it  
> only gives some kind of the biggest/smallest times but not percentiles ☹  
> _Question:_ Is it possible to take that value from another aggreagation?
> 
> Thank you for any answer 🙂
> 
> Regards,  
> Marek Skorek.
> 
> --  
> 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/c4bc31ad-ca6e-4041-89b2-ae09fb12a2c0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c4bc31ad-ca6e-4041-89b2-ae09fb12a2c0%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/c4bc31ad-ca6e-4041-89b2-ae09fb12a2c0%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c4bc31ad-ca6e-4041-89b2-ae09fb12a2c0%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
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/CAL6Z4j6XtAu\_FazHzfLPxGP1CkWBiy\_mC9K4n5aMA8J629sjTA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j6XtAu_FazHzfLPxGP1CkWBiy_mC9K4n5aMA8J629sjTA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Antonio\_Augusto\_Sant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/antonio_augusto_sant/32/82851_2.png) [@Antonio\_Augusto\_Sant](https://discuss.elastic.co/u/Antonio_Augusto_Sant)\
**Post date:** [June 11, 2014, 3:10pm UTC](https://discuss.elastic.co/t/sub-aggregations-percentiles-of-sum/18012/3 "2014-06-11T15:10:03Z")

</div>

Pretty, pretty, pretty please? 😉  
I'd also be interested in something like this, so I can do percentiles  
based on documents count aggregation, for example, without having to  
reparse/reindex everything.

On Wednesday, June 11, 2014 12:01:56 PM UTC-3, Adrien Grand wrote:

> Hi,
> 
> This is a feature that we are considering but it is unfortunately not  
> available for the moment.
> 
> On Tue, Jun 10, 2014 at 11:33 AM, Marek Skorek \<[sco...@gmail.com](mailto:sco...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Hi,
> > 
> > I have a question about subaggregations.
> > 
> > The case is that I have small documents (single opratations) with  
> > duration time of this operation which I want to aggregate and finally get  
> > the percentile of this sum.
> > 
> > Example:  
> > | operation | time |  
> > | A | 10 |  
> > | A | 20 |  
> > | B | 100 |  
> > | B | 1000 |  
> > | C | 10 |  
> > | C | 10 |
> > 
> > _Request:_  
> > {  
> > "aggs": {  
> > "by\_operation": {  
> > "terms" : {  
> > "field" : "operation"  
> > },  
> > "aggs" : {  
> > "sum\_times" : {  
> > "sum" : { "field" : "time"}  
> > }  
> > }  
> > }  
> > },  
> > "size" : 0  
> > }
> > 
> > _Results:_  
> > { ...  
> > "aggregations": {  
> > "by\_operation": {  
> > "buckets": [{  
> > "key": "a",  
> > "doc\_count": 2,  
> > "sum\_times": {  
> > "value": 30.0  
> > }  
> > },  
> > {  
> > "key": "c",  
> > "doc\_count": 2,  
> > "sum\_times": {  
> > "value": 20.0  
> > }  
> > },  
> > {  
> > "key": "b",  
> > "doc\_count": 2,  
> > "sum\_times": {  
> > "value": 1100.0  
> > }  
> > }]  
> > }  
> > }  
> > }
> > 
> > After that it will be nice to have i.e. percentile of the field  
> > _sum\_times_. I know it can be ordered by the "sum\_times" aggregate but  
> > it only gives some kind of the biggest/smallest times but not percentiles ☹  
> > _Question:_ Is it possible to take that value from another aggreagation?
> > 
> > Thank you for any answer 🙂
> > 
> > Regards,  
> > Marek Skorek.
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/c4bc31ad-ca6e-4041-89b2-ae09fb12a2c0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c4bc31ad-ca6e-4041-89b2-ae09fb12a2c0%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/c4bc31ad-ca6e-4041-89b2-ae09fb12a2c0%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c4bc31ad-ca6e-4041-89b2-ae09fb12a2c0%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Adrien Grand

--  
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/530cea06-4bed-4fa8-8221-fe10c6d02e1e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/530cea06-4bed-4fa8-8221-fe10c6d02e1e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Marek\_Skorek](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Marek\_Skorek](https://discuss.elastic.co/u/Marek_Skorek)\
**Post date:** [June 11, 2014, 6:05pm UTC](https://discuss.elastic.co/t/sub-aggregations-percentiles-of-sum/18012/4 "2014-06-11T18:05:50Z")

</div>

Adrien,

I am looking forward to this feature and you will manage it quite fast 🙂

Again, thank you for an answer. You save my time.

W dniu wtorek, 10 czerwca 2014 11:33:26 UTC+2 użytkownik Marek Skorek  
napisał:

> Hi,
> 
> I have a question about subaggregations.
> 
> The case is that I have small documents (single opratations) with duration  
> time of this operation which I want to aggregate and finally get the  
> percentile of this sum.
> 
> Example:  
> | operation | time |  
> | A | 10 |  
> | A | 20 |  
> | B | 100 |  
> | B | 1000 |  
> | C | 10 |  
> | C | 10 |
> 
> _Request:_  
> {  
> "aggs": {  
> "by\_operation": {  
> "terms" : {  
> "field" : "operation"  
> },  
> "aggs" : {  
> "sum\_times" : {  
> "sum" : { "field" : "time"}  
> }  
> }  
> }  
> },  
> "size" : 0  
> }
> 
> _Results:_  
> { ...  
> "aggregations": {  
> "by\_operation": {  
> "buckets": [{  
> "key": "a",  
> "doc\_count": 2,  
> "sum\_times": {  
> "value": 30.0  
> }  
> },  
> {  
> "key": "c",  
> "doc\_count": 2,  
> "sum\_times": {  
> "value": 20.0  
> }  
> },  
> {  
> "key": "b",  
> "doc\_count": 2,  
> "sum\_times": {  
> "value": 1100.0  
> }  
> }]  
> }  
> }  
> }
> 
> After that it will be nice to have i.e. percentile of the field  
> _sum\_times_. I know it can be ordered by the "sum\_times" aggregate but it  
> only gives some kind of the biggest/smallest times but not percentiles ☹  
> _Question:_ Is it possible to take that value from another aggreagation?
> 
> Thank you for any answer 🙂
> 
> Regards,  
> Marek Skorek.

--  
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/a1c47939-810d-4194-90df-6b22bbe45f6e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a1c47939-810d-4194-90df-6b22bbe45f6e%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:23am UTC](https://discuss.elastic.co/t/sub-aggregations-percentiles-of-sum/18012/5 "2017-07-06T01:23:11Z")

</div>


