# Limit results based on percentage of sum aggregation

**URL:** <https://discuss.elastic.co/t/limit-results-based-on-percentage-of-sum-aggregation/179844>\
**Category:** Elasticsearch\
**Created:** [May 6, 2019, 9:22pm UTC](https://discuss.elastic.co/t/limit-results-based-on-percentage-of-sum-aggregation/179844 "2019-05-06T21:22:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmarques](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pmarques/32/42536_2.png) [@pmarques](https://discuss.elastic.co/u/pmarques)\
**Post date:** [May 6, 2019, 9:22pm UTC](https://discuss.elastic.co/t/limit-results-based-on-percentage-of-sum-aggregation/179844/1 "2019-05-06T21:22:31Z")

</div>

Hello All,

My goal is to limit the results based on a percentage of a sum aggregation. I will try to clarify it with an example.

{ "name": "A", "value": 10 }  
{ "name": "B", "value": 20 }  
{ "name": "B", "value": 35 }  
{ "name": "A", "value": 15 }  
{ "name": "C", "value": 15 }  
{ "name": "A", "value": 10 }  
{ "name": "C", "value": 5 }  
{ "name": "A", "value": 10 }  
{ "name": "D", "value": 15 }  
{ "name": "A", "value": 30 }  
{ "name": "E", "value": 1 }  
(...)

Aggregating the data above,

{ "name": "A", "value": 70 }  
{ "name": "B", "value": 60 }  
{ "name": "C", "value": 50 }  
{ "name": "D", "value": 45 }  
{ "name": "E", "value": 40 }  
(...)

Imagine that the sum of all values is equal to 640

I would like to show the items that together they represent 20% (or a bit more) of 640

640 \* (20/100) = 128

So, the result that I would like to have is:

{ "name": "A", "value": 70 }  
{ "name": "B", "value": 60 }

I will appreciate any thoughts.

Cheers,  
Paulo

---

<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:** [June 3, 2019, 9:22pm UTC](https://discuss.elastic.co/t/limit-results-based-on-percentage-of-sum-aggregation/179844/2 "2019-06-03T21:22:31Z")

</div>

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