# Can we use the ouput of query as input to other in same API request?

**URL:** <https://discuss.elastic.co/t/can-we-use-the-ouput-of-query-as-input-to-other-in-same-api-request/37915>\
**Category:** Elasticsearch\
**Created:** [December 24, 2015, 7:32am UTC](https://discuss.elastic.co/t/can-we-use-the-ouput-of-query-as-input-to-other-in-same-api-request/37915 "2015-12-24T07:32:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![trushad](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@trushad](https://discuss.elastic.co/u/trushad)\
**Post date:** [December 24, 2015, 7:32am UTC](https://discuss.elastic.co/t/can-we-use-the-ouput-of-query-as-input-to-other-in-same-api-request/37915/1 "2015-12-24T07:32:35Z")

</div>

{  
"size":0,  
"aggs" : {  
"avg\_speed" : {"max" : {"field" : "Speed" } }  
}  
}

* * *

{  
"query": {  
"bool": {  
"must": [  
{  
"range":{  
"Speed":{  
"gte":{"avg\_speed"}  
}  
}  
}  
]  
}  
}  
Can i club above two queries? I want to use avg\_speed computed in first query in the next range query, is their any functionality like this?  
Problem domain is: I want to compute documents that have speed range greater then average speed

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [December 24, 2015, 10:55am UTC](https://discuss.elastic.co/t/can-we-use-the-ouput-of-query-as-input-to-other-in-same-api-request/37915/2 "2015-12-24T10:55:44Z")

</div>

There is no way to do this in a single request.

---

<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 5, 2017, 11:28pm UTC](https://discuss.elastic.co/t/can-we-use-the-ouput-of-query-as-input-to-other-in-same-api-request/37915/3 "2017-07-05T23:28:52Z")

</div>

Closed on July 5, 2017, 11:28pm UTC


