# Use output of one query in as input in another

**URL:** <https://discuss.elastic.co/t/use-output-of-one-query-in-as-input-in-another/27481>\
**Category:** Elasticsearch\
**Created:** [August 17, 2015, 8:09am UTC](https://discuss.elastic.co/t/use-output-of-one-query-in-as-input-in-another/27481 "2015-08-17T08:09:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ankit\_Pradhan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ankit_pradhan/32/44412_2.png) [@Ankit\_Pradhan](https://discuss.elastic.co/u/Ankit_Pradhan)\
**Post date:** [August 17, 2015, 8:09am UTC](https://discuss.elastic.co/t/use-output-of-one-query-in-as-input-in-another/27481/1 "2015-08-17T08:09:01Z")

</div>

I would like to use the out of One query as input in another but dont know how.

For example:

Index1: (Field 1, Field 2, Field 3)

Index2: (Field 3, Field 4, Field 5)

Select Field 2 from from Index1 where Field 3 = (select Field 3 from Index 2 where Field 5 = 'user input'))

Basically this goes towards joining two indexes .. and getting the results from two indexes in one query. I am not sure if this is possible in ES.  
One easy way would be to merge Index 1 and Index 2 in one but that's not the possibility in the use case as the source are different for both.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 17, 2015, 8:21am UTC](https://discuss.elastic.co/t/use-output-of-one-query-in-as-input-in-another/27481/2 "2015-08-17T08:21:07Z")

</div>

You cannot currently do this.

Pipeline aggs in 2.0 will let you do some of it though/

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [August 18, 2015, 9:47am UTC](https://discuss.elastic.co/t/use-output-of-one-query-in-as-input-in-another/27481/3 "2015-08-18T09:47:44Z")

</div>

Pipeline aggs will not help here unfortunately. Pipeline aggregations let you perform extra computation on the results of an aggregation but do not let you performs joins between results from separate indices.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 18, 2015, 9:46pm UTC](https://discuss.elastic.co/t/use-output-of-one-query-in-as-input-in-another/27481/4 "2015-08-18T21:46:30Z")

</div>

Ahh bummer ☹

---

<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:55pm UTC](https://discuss.elastic.co/t/use-output-of-one-query-in-as-input-in-another/27481/5 "2017-07-05T23:55:11Z")

</div>


