# Percentile after aggregation

**URL:** <https://discuss.elastic.co/t/percentile-after-aggregation/302245>\
**Category:** Elasticsearch\
**Created:** [April 12, 2022, 2:06pm UTC](https://discuss.elastic.co/t/percentile-after-aggregation/302245 "2022-04-12T14:06:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Hornsby](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robert_hornsby/32/99407_2.png) [@Robert\_Hornsby](https://discuss.elastic.co/u/Robert_Hornsby)\
**Post date:** [April 12, 2022, 2:06pm UTC](https://discuss.elastic.co/t/percentile-after-aggregation/302245/1 "2022-04-12T14:06:04Z")

</div>

My data is a series of document each with a time and a transaction id. I want to group the data by transaction id, from each group select the largest time and then use those times as input to a percentile function. I can get the list of times using the SQL style syntax like this

"query": "select time from (SELECT max("time") as time, count(\*) as count, "transactionId" FROM "test-logs" group by transactionId) where count \> 1)"

However when I try to calculate a percentile on that data like this

"query": "select percentile(time, 50) from (SELECT max("time") as time, count(\*) as count, "transactionId" FROM "test-logs" group by transactionId) where count \> 1)"

I get the error "Nested aggregations in sub-selects are not supported."  
I have tried to find a way to do the same thing with the DSL but I have not been able to figure it out, could anyone suggest a way forward?

---

<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 10, 2022, 2:06pm UTC](https://discuss.elastic.co/t/percentile-after-aggregation/302245/2 "2022-05-10T14:06:14Z")

</div>

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