# Percentile based on aggregated data

**URL:** <https://discuss.elastic.co/t/percentile-based-on-aggregated-data/23362>\
**Category:** Elasticsearch\
**Created:** [April 22, 2015, 1:49pm UTC](https://discuss.elastic.co/t/percentile-based-on-aggregated-data/23362 "2015-04-22T13:49:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![imarkoffko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/imarkoffko/32/744_2.png) [@imarkoffko](https://discuss.elastic.co/u/imarkoffko)\
**Post date:** [April 22, 2015, 1:49pm UTC](https://discuss.elastic.co/t/percentile-based-on-aggregated-data/23362/1 "2015-04-22T13:49:48Z")

</div>

My problem:  
There are a lot of documents with the following structure (example):

{"someId" : 1, "someCounter": 2}  
{"someId" : 1, "someCounter": 1}  
{"someId" : 2, "someCounter": 3}  
{"someId" : 3, "someCounter": 5}  
{"someId" : 3, "someCounter": 1}  
{"someId" : 3, "someCounter": 3}

I want to calculate the percentile of the amount of the \*someCounter \*grouped  
by _someId_:

Request example

"aggs": {  
"someId": {  
"terms": {  
"field": "someId"  
},  
"aggs": {  
"someCounter\_sum": {  
"sum": {  
"field": "someCounter"  
},  
"aggs": {  
"percentile": {  
"percentiles": {  
// ?  
}  
}  
}  
}  
}  
}  
}

Response example

"aggregations": {  
"name": {  
"percentile": {  
"99.0": 0.001  
}  
}  
}

I’m trying to aggregate with _terms_, _sum_ and _percentiles_, but I’m not  
sure if it is possible. I also tried _script field_ with the same result.  
Is it possible to calculate percentile based on aggregated data on  
elasticsearch?

--  
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/a1831d55-d521-42bc-a846-a6211c6f19a0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a1831d55-d521-42bc-a846-a6211c6f19a0%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, 12:18am UTC](https://discuss.elastic.co/t/percentile-based-on-aggregated-data/23362/2 "2017-07-06T00:18:18Z")

</div>


