# Question about Query DSL in ElasticSearch

**URL:** <https://discuss.elastic.co/t/question-about-query-dsl-in-elasticsearch/23363>\
**Category:** Elasticsearch\
**Created:** [April 22, 2015, 2:11pm UTC](https://discuss.elastic.co/t/question-about-query-dsl-in-elasticsearch/23363 "2015-04-22T14:11:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tiago\_Filipe](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@Tiago\_Filipe](https://discuss.elastic.co/u/Tiago_Filipe)\
**Post date:** [April 22, 2015, 2:11pm UTC](https://discuss.elastic.co/t/question-about-query-dsl-in-elasticsearch/23363/1 "2015-04-22T14:11:27Z")

</div>

I'm new to ElasticSearch and I'm struggling with this question. Basically  
what I want to do is sort of like this (SQL Example):

SELECT A.id  
FROM TableA A, TableB B  
WHERE A.id = B.id;

I want a Query that returns all of the info from TableA, but only if the id  
from TableA is equal to an id from TableB. I've read a lot of Query Filter  
fields and I think I might use the Term Field  
[http://www.elastic.co/guide/en/elasticsearch/reference/1.x/query-dsl-term-query.html](http://www.elastic.co/guide/en/elasticsearch/reference/1.x/query-dsl-term-query.html) but  
I'm not sure how.

Thanks in advance!

--  
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/1ad75f69-8623-4dcf-a58c-2a9bfa0eb4a7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1ad75f69-8623-4dcf-a58c-2a9bfa0eb4a7%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:** [April 22, 2015, 3:07pm UTC](https://discuss.elastic.co/t/question-about-query-dsl-in-elasticsearch/23363/2 "2015-04-22T15:07:45Z")

</div>

This SQL query is a join and in general elasticsearch does not support  
joins.

If the id field is your PK, you might be able to do it by indexing B as a  
child of A (using parent/child) and then searching for all documents in A  
that have a child in B.

On Wed, Apr 22, 2015 at 4:11 PM, Tiago Filipe [odecaracois@gmail.com](mailto:odecaracois@gmail.com) wrote:

> I'm new to Elasticsearch and I'm struggling with this question. Basically  
> what I want to do is sort of like this (SQL Example):
> 
> SELECT A.id  
> FROM TableA A, TableB B  
> WHERE A.id = B.id;
> 
> I want a Query that returns all of the info from TableA, but only if the  
> id from TableA is equal to an id from TableB. I've read a lot of Query  
> Filter fields and I think I might use the Term Field  
> [http://www.elastic.co/guide/en/elasticsearch/reference/1.x/query-dsl-term-query.html](http://www.elastic.co/guide/en/elasticsearch/reference/1.x/query-dsl-term-query.html) but  
> I'm not sure how.
> 
> Thanks in advance!
> 
> --  
> 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/1ad75f69-8623-4dcf-a58c-2a9bfa0eb4a7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1ad75f69-8623-4dcf-a58c-2a9bfa0eb4a7%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/1ad75f69-8623-4dcf-a58c-2a9bfa0eb4a7%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/1ad75f69-8623-4dcf-a58c-2a9bfa0eb4a7%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

--  
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/CAO5%3DkAh33ecJ%3DbOmakfopgaDMCn7Lw%2BENjQvx0bV%3Dk5%3DQnUR3A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAO5%3DkAh33ecJ%3DbOmakfopgaDMCn7Lw%2BENjQvx0bV%3Dk5%3DQnUR3A%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Tiago\_Filipe](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@Tiago\_Filipe](https://discuss.elastic.co/u/Tiago_Filipe)\
**Post date:** [April 22, 2015, 3:49pm UTC](https://discuss.elastic.co/t/question-about-query-dsl-in-elasticsearch/23363/3 "2015-04-22T15:49:41Z")

</div>

Thanks for the reply.

I already found another solution though (not related to Elasticsearch)

Thanks again.

Em quarta-feira, 22 de abril de 2015 16:07:54 UTC+1, Adrien Grand escreveu:

> This SQL query is a join and in general elasticsearch does not support  
> joins.
> 
> If the id field is your PK, you might be able to do it by indexing B as a  
> child of A (using parent/child) and then searching for all documents in A  
> that have a child in B.
> 
> On Wed, Apr 22, 2015 at 4:11 PM, Tiago Filipe \<[odeca...@gmail.com](mailto:odeca...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > I'm new to Elasticsearch and I'm struggling with this question. Basically  
> > what I want to do is sort of like this (SQL Example):
> > 
> > SELECT A.id  
> > FROM TableA A, TableB B  
> > WHERE A.id = B.id;
> > 
> > I want a Query that returns all of the info from TableA, but only if the  
> > id from TableA is equal to an id from TableB. I've read a lot of Query  
> > Filter fields and I think I might use the Term Field  
> > [http://www.elastic.co/guide/en/elasticsearch/reference/1.x/query-dsl-term-query.html](http://www.elastic.co/guide/en/elasticsearch/reference/1.x/query-dsl-term-query.html) but  
> > I'm not sure how.
> > 
> > Thanks in advance!
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/1ad75f69-8623-4dcf-a58c-2a9bfa0eb4a7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1ad75f69-8623-4dcf-a58c-2a9bfa0eb4a7%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/1ad75f69-8623-4dcf-a58c-2a9bfa0eb4a7%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/1ad75f69-8623-4dcf-a58c-2a9bfa0eb4a7%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

--  
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/62075aad-fab9-4ef1-8f91-d44e6530b691%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/62075aad-fab9-4ef1-8f91-d44e6530b691%40googlegroups.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:18am UTC](https://discuss.elastic.co/t/question-about-query-dsl-in-elasticsearch/23363/4 "2017-07-06T00:18:15Z")

</div>


