# Holding aggregation results in parameters

**URL:** <https://discuss.elastic.co/t/holding-aggregation-results-in-parameters/16541>\
**Category:** Elasticsearch\
**Created:** [March 22, 2014, 7:44am UTC](https://discuss.elastic.co/t/holding-aggregation-results-in-parameters/16541 "2014-03-22T07:44:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amit\_Soni](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Amit\_Soni](https://discuss.elastic.co/u/Amit_Soni)\
**Post date:** [March 22, 2014, 7:44am UTC](https://discuss.elastic.co/t/holding-aggregation-results-in-parameters/16541/1 "2014-03-22T07:44:29Z")

</div>

Hi all - I have been trying to do the following using aggregations but have  
been unable to and any help on this would be really great.

Assume that my document has two fields: A and B. I want to do the following:

1. Get max (A)
2. Get max (B)
3. Take difference of #1 and #2
4. Get the count of all documents for which the difference (computed in  
#3) is more than say 'x'

Does aggregation support execution of stuff like above where I believe I  
will have to temporarily store the values in a variable and then use it in  
the next filter (more like a nested query).

thoughts?  
-Amit.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAAOGaQLoT%2BKXAyFRsEiZOD\_hy%3D4nf2WKB61ysO7XF5BJvQzkEA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAOGaQLoT%2BKXAyFRsEiZOD_hy%3D4nf2WKB61ysO7XF5BJvQzkEA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)\
**Post date:** [March 24, 2014, 4:50pm UTC](https://discuss.elastic.co/t/holding-aggregation-results-in-parameters/16541/2 "2014-03-24T16:50:12Z")

</div>

Trying to understand your question, when you say max(A) or max(B), do you  
mean you have multiple values in A or B per document?

Also, it "sounds" to me like you want a script\_filter instead of an  
aggregation:

[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-script-filter.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-script-filter.html)

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0b002205-304c-460f-b8f1-808e45658283%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0b002205-304c-460f-b8f1-808e45658283%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Amit\_Soni](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@Amit\_Soni](https://discuss.elastic.co/u/Amit_Soni)\
**Post date:** [March 31, 2014, 6:59am UTC](https://discuss.elastic.co/t/holding-aggregation-results-in-parameters/16541/3 "2014-03-31T06:59:07Z")

</div>

Hi Binh - Apology for the late reply. By max(A) I mean maximum value of a  
field A and A can have multiple values. My document would have both field A  
and field B.

-Amit.

On Mon, Mar 24, 2014 at 9:50 AM, Binh Ly [binhly\_es@yahoo.com](mailto:binhly_es@yahoo.com) wrote:

> Trying to understand your question, when you say max(A) or max(B), do you  
> mean you have multiple values in A or B per document?
> 
> Also, it "sounds" to me like you want a script\_filter instead of an  
> aggregation:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-script-filter.html)
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/0b002205-304c-460f-b8f1-808e45658283%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0b002205-304c-460f-b8f1-808e45658283%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/0b002205-304c-460f-b8f1-808e45658283%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/0b002205-304c-460f-b8f1-808e45658283%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAAOGaQJW3PTDEuApiZiW%2BoQjjvj2NQx1BNo%2BJsfmvxX5bxE%3DXg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAOGaQJW3PTDEuApiZiW%2BoQjjvj2NQx1BNo%2BJsfmvxX5bxE%3DXg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:39am UTC](https://discuss.elastic.co/t/holding-aggregation-results-in-parameters/16541/4 "2017-07-06T01:39:35Z")

</div>


