# Filter outliers elastic 5

**URL:** <https://discuss.elastic.co/t/filter-outliers-elastic-5/71947>\
**Category:** Elasticsearch\
**Created:** [January 18, 2017, 8:03am UTC](https://discuss.elastic.co/t/filter-outliers-elastic-5/71947 "2017-01-18T08:03:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![liorg2](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@liorg2](https://discuss.elastic.co/u/liorg2)\
**Post date:** [January 18, 2017, 8:03am UTC](https://discuss.elastic.co/t/filter-outliers-elastic-5/71947/1 "2017-01-18T08:03:47Z")

</div>

whats is the best way to do the following query in elastic 5.x:

find the average of a field, _after_ removing the top 5% highest values (\> 95th percentile) ?

I'm looking a single query solution

thanks!

---

<div class="post-metadata">

**Author:** ![mainec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mainec/32/5557_2.png) [@mainec](https://discuss.elastic.co/u/mainec)\
**Post date:** [January 18, 2017, 11:17am UTC](https://discuss.elastic.co/t/filter-outliers-elastic-5/71947/2 "2017-01-18T11:17:49Z")

</div>

> [@liorg2](#):
>
> I'm looking a single query solution

Can you elaborate on what's your reason for doing this in one query?

If that's not a hard requirement, you could be using percentile aggregations/ average aggregations in separate queries.

Isabel

---

<div class="post-metadata">

**Author:** ![liorg2](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@liorg2](https://discuss.elastic.co/u/liorg2)\
**Post date:** [January 18, 2017, 9:00pm UTC](https://discuss.elastic.co/t/filter-outliers-elastic-5/71947/3 "2017-01-18T21:00:21Z")

</div>

My purpose is to remove outliers, and get the avarage of values, lower than 90th percentile or so,

This aggregation is a child of several parent terms aggregations.

If i have to run 2 queries for the purpose above, I will need to run another query for each dimension combination.

For example:  
In case of parent terms aggregations of the following dimensions: city, country, page device,  
If we assume 1000 combinations,  
After getting the 95th percentile value from the first query, I will need to run another query with filter of the above dimensions and also filter of value \< 95 percentile X 1000 options

---

<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 15, 2017, 9:00pm UTC](https://discuss.elastic.co/t/filter-outliers-elastic-5/71947/4 "2017-02-15T21:00:30Z")

</div>

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