# Subtraction of 90th and 10th percentile (percentile range)

**URL:** <https://discuss.elastic.co/t/subtraction-of-90th-and-10th-percentile-percentile-range/197910>\
**Category:** Elasticsearch\
**Created:** [September 3, 2019, 4:33pm UTC](https://discuss.elastic.co/t/subtraction-of-90th-and-10th-percentile-percentile-range/197910 "2019-09-03T16:33:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piotr\_Wasilewski](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/piotr_wasilewski/32/35347_2.png) [@Piotr\_Wasilewski](https://discuss.elastic.co/u/Piotr_Wasilewski)\
**Post date:** [September 3, 2019, 4:33pm UTC](https://discuss.elastic.co/t/subtraction-of-90th-and-10th-percentile-percentile-range/197910/1 "2019-09-03T16:33:49Z")

</div>

Hi,

I was asked to create a query for records with response times in range between 10th and 90th percentile. These data are in single numeric field in documents.

I know I can get both of them with aggregation query, but I need to get value of range (90-10)th percentile and I was wondering if that is at all possible in single query without need of performing any additional computations on results.

with something like this:

```
"aggs":{"1":{"percentiles":{"field":"json.@fields.duration_ms","percents":["10","90"]}}

```

I'm getting two separate series of data instead of one, which I'm aiming for.

Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [September 9, 2019, 5:48pm UTC](https://discuss.elastic.co/t/subtraction-of-90th-and-10th-percentile-percentile-range/197910/2 "2019-09-09T17:48:41Z")

</div>

I _think_ it is doable with a [`bucket_script`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html) pipeline agg. E.g. the current percentiles aggregation that you have with `90` and `10` percentiles specified, then use the `bucket_script` to subtract one from the other.

On the run at the moment so I can't work up an example, but let me know if you have difficulties and I can try to make a demo when I'm back at the office 🙂

---

<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:** [October 7, 2019, 5:48pm UTC](https://discuss.elastic.co/t/subtraction-of-90th-and-10th-percentile-percentile-range/197910/3 "2019-10-07T17:48:42Z")

</div>

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