# Question about SubQueries

**URL:** <https://discuss.elastic.co/t/question-about-subqueries/20767>\
**Category:** Elasticsearch\
**Created:** [November 16, 2014, 4:10pm UTC](https://discuss.elastic.co/t/question-about-subqueries/20767 "2014-11-16T16:10:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bud\_Spencer](https://avatars.discourse-cdn.com/v4/letter/b/df705f/32.png) [@Bud\_Spencer](https://discuss.elastic.co/u/Bud_Spencer)\
**Post date:** [November 16, 2014, 4:10pm UTC](https://discuss.elastic.co/t/question-about-subqueries/20767/1 "2014-11-16T16:10:28Z")

</div>

Hi ES-Team,

i have a question if there is a plan to enable subqueries in ES in the  
future.

I would be greate to use one query as input for a other query, e.g to get  
all ID's of one query and search with them in a other query

Perhaps i should explain what i am trying to do:

I have a index e.g "myIndex" with 2 types of documents "typeOne" and  
"typeTwo".  
"typeTwo"-documents contain on ID of "typeOne"-documents. Now i want to  
search in "typeOne"-documents where e.g. in find the word "test" and only  
in the documents where the ID is in the documents of "typeTwo", like i a  
DB.

Is there any way to achive this goal for now (i know 2 queries would do  
this, but this is not my question) in one query? I know that for now ES  
does not support sub queries but in future?

Best regards  
Bud Spencer

--  
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/8d6f9740-e226-4503-a9ab-ea63b8186a51%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8d6f9740-e226-4503-a9ab-ea63b8186a51%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [November 17, 2014, 11:04am UTC](https://discuss.elastic.co/t/question-about-subqueries/20767/2 "2014-11-17T11:04:52Z")

</div>

Hi Bud,

It seems to me that what you are looking for is a join. Elasticsearch only  
has limited support for joins, mainly through nested documents and  
parent/child relations.[1] It does not support general-purpose joins  
because such operations tend to be very costly/slow in a distributed  
environment.

[1]

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Sun, Nov 16, 2014 at 5:10 PM, Bud Spencer [xmansjo@web.de](mailto:xmansjo@web.de) wrote:

> Hi ES-Team,
> 
> i have a question if there is a plan to enable subqueries in ES in the  
> future.
> 
> I would be greate to use one query as input for a other query, e.g to get  
> all ID's of one query and search with them in a other query
> 
> Perhaps i should explain what i am trying to do:
> 
> I have a index e.g "myIndex" with 2 types of documents "typeOne" and  
> "typeTwo".  
> "typeTwo"-documents contain on ID of "typeOne"-documents. Now i want to  
> search in "typeOne"-documents where e.g. in find the word "test" and only  
> in the documents where the ID is in the documents of "typeTwo", like i a  
> DB.
> 
> Is there any way to achive this goal for now (i know 2 queries would do  
> this, but this is not my question) in one query? I know that for now ES  
> does not support sub queries but in future?
> 
> Best regards  
> Bud Spencer
> 
> --  
> 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/8d6f9740-e226-4503-a9ab-ea63b8186a51%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8d6f9740-e226-4503-a9ab-ea63b8186a51%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/8d6f9740-e226-4503-a9ab-ea63b8186a51%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/8d6f9740-e226-4503-a9ab-ea63b8186a51%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
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/CAL6Z4j5MtMT%3Dr2W88OSFABQxkJu3pP9NK-3nbZ4td8GJjUe%3D9w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5MtMT%3Dr2W88OSFABQxkJu3pP9NK-3nbZ4td8GJjUe%3D9w%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, 12:49am UTC](https://discuss.elastic.co/t/question-about-subqueries/20767/3 "2017-07-06T00:49:36Z")

</div>


