# Aggregation time complexity

**URL:** <https://discuss.elastic.co/t/aggregation-time-complexity/260925>\
**Category:** Elasticsearch\
**Created:** [January 13, 2021, 3:02am UTC](https://discuss.elastic.co/t/aggregation-time-complexity/260925 "2021-01-13T03:02:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![isbee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/isbee/32/82132_2.png) [@isbee](https://discuss.elastic.co/u/isbee)\
**Post date:** [January 13, 2021, 3:02am UTC](https://discuss.elastic.co/t/aggregation-time-complexity/260925/1 "2021-01-13T03:02:32Z")

</div>

I want to aggregate N(= 10 million) data by `percentile_rank`. And I want to call this query lively (more than 100 times per second).

As far as I know, Elasticsearch uses t-digest algorithm on percentile. So total time complexity is O(NlogN).

My question is, does this time complexity applies on every single `percentile_rank` query? Is there any optimization like caching(if no PUT happens), periodical sort(maybe once an hour)?

If there is no optimization, can Elasticsearch handle our query scale effectively?

---

<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:** [February 10, 2021, 3:02am UTC](https://discuss.elastic.co/t/aggregation-time-complexity/260925/2 "2021-02-10T03:02:32Z")

</div>

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