# Above average

**URL:** https://discuss.elastic.co/t/above-average/135010
**Category:** Elasticsearch
**Created:** [June 7, 2018, 2:16pm UTC](https://discuss.elastic.co/t/above-average/135010 "2018-06-07T14:16:08Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![himberjack](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/himberjack/32/48211_2.png) [@himberjack](https://discuss.elastic.co/u/himberjack)
#### Post date: [June 7, 2018, 2:16pm UTC](https://discuss.elastic.co/t/above-average/135010/1 "2018-06-07T14:16:08Z")

</div>

Hi,

We have simple keywords in our docs with dates.  
We would like to get all terms that were in a range of dates (14 days) that are above their monthly average of occurrences.

Is that possible?  
How

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [June 7, 2018, 4:03pm UTC](https://discuss.elastic.co/t/above-average/135010/2 "2018-06-07T16:03:32Z")

</div>

I think you need to fire 2 queries for that.

The first will compute the average.  
The second will search for documents above.

---

<div class="post-metadata">

### Author: ![himberjack](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/himberjack/32/48211_2.png) [@himberjack](https://discuss.elastic.co/u/himberjack)
#### Post date: [June 10, 2018, 9:50am UTC](https://discuss.elastic.co/t/above-average/135010/3 "2018-06-10T09:50:56Z")

</div>

What do you mean? If I have 1m docs, that I want to pull the highest above average in the last 14 days? how can I pipe this into 2 queries?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [June 11, 2018, 8:49am UTC](https://discuss.elastic.co/t/above-average/135010/4 "2018-06-11T08:49:48Z")

</div>

May be I did not get exactly the use case.

I'd filter the last month of data and compute an average aggregation.

Read that value from the response.

Then run a date range filter to select the last 14 days and apply as well a range filter where the value is above the value we got with the previous query.

---

<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: [July 9, 2018, 8:49am UTC](https://discuss.elastic.co/t/above-average/135010/5 "2018-07-09T08:49:48Z")

</div>

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