# (no subject)

**URL:** <https://discuss.elastic.co/t/no-subject/7171>\
**Category:** Elasticsearch\
**Created:** [March 29, 2012, 12:57pm UTC](https://discuss.elastic.co/t/no-subject/7171 "2012-03-29T12:57:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhishek\_Jajoria](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@Abhishek\_Jajoria](https://discuss.elastic.co/u/Abhishek_Jajoria)\
**Post date:** [March 29, 2012, 12:57pm UTC](https://discuss.elastic.co/t/no-subject/7171/1 "2012-03-29T12:57:46Z")

</div>

How can we apply sql joins in elasticsearch queries  
like

SELECT \* FROM Persons  
RIGHT JOIN Orders  
ON Persons.P\_Id=Orders.P\_Id

I have two index with types persons and Orders  
related with each other using P\_ID field.

---

<div class="post-metadata">

**Author:** ![Shaun\_Farrell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shaun_farrell/32/2827_2.png) [@Shaun\_Farrell](https://discuss.elastic.co/u/Shaun_Farrell)\
**Post date:** [March 29, 2012, 11:21pm UTC](https://discuss.elastic.co/t/no-subject/7171/2 "2012-03-29T23:21:22Z")

</div>

You need to flatten this. Either put order Ids in the person or the person ids in the orders

Sent from my iPhone

On Mar 29, 2012, at 7:57 AM, jajoria abhishek [jajoria.abhishek@gmail.com](mailto:jajoria.abhishek@gmail.com) wrote:

> How can we apply sql joins in elasticsearch queries  
> like
> 
> SELECT \* FROM Persons  
> RIGHT JOIN Orders  
> ON Persons.P\_Id=Orders.P\_Id
> 
> I have two index with types persons and Orders  
> related with each other using P\_ID field.

---

<div class="post-metadata">

**Author:** ![Abhishek\_Jajoria](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@Abhishek\_Jajoria](https://discuss.elastic.co/u/Abhishek_Jajoria)\
**Post date:** [March 30, 2012, 4:55am UTC](https://discuss.elastic.co/t/no-subject/7171/3 "2012-03-30T04:55:47Z")

</div>

But in this case you have to alter the index mapping and you have to Index  
according to queries.  
On Fri, Mar 30, 2012 at 4:51 AM, Shaun Farrell [farrelley@gmail.com](mailto:farrelley@gmail.com) wrote:

> You need to flatten this. Either put order Ids in the person or the person  
> ids in the orders
> 
> Sent from my iPhone
> 
> On Mar 29, 2012, at 7:57 AM, jajoria abhishek [jajoria.abhishek@gmail.com](mailto:jajoria.abhishek@gmail.com)  
> wrote:
> 
> > How can we apply sql joins in elasticsearch queries  
> > like
> > 
> > SELECT \* FROM Persons  
> > RIGHT JOIN Orders  
> > ON Persons.P\_Id=Orders.P\_Id
> > 
> > I have two index with types persons and Orders  
> > related with each other using P\_ID field.

---

<div class="post-metadata">

**Author:** ![Thomas\_Peuss](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@Thomas\_Peuss](https://discuss.elastic.co/u/Thomas_Peuss)\
**Post date:** [March 30, 2012, 6:46am UTC](https://discuss.elastic.co/t/no-subject/7171/4 "2012-03-30T06:46:38Z")

</div>

Hi Abhishek!

Am Freitag, 30. März 2012 06:55:47 UTC+2 schrieb jajoria abhishek:

> But in this case you have to alter the index mapping and you have to  
> Index according to queries.

Exactly. Like in any other NoSQL-DB as well. 😉

CU  
Thomas

---

<div class="post-metadata">

**Author:** ![Abhishek\_Jajoria](https://avatars.discourse-cdn.com/v4/letter/a/b5e925/32.png) [@Abhishek\_Jajoria](https://discuss.elastic.co/u/Abhishek_Jajoria)\
**Post date:** [March 30, 2012, 7:10am UTC](https://discuss.elastic.co/t/no-subject/7171/5 "2012-03-30T07:10:29Z")

</div>

Thanks for your responses

On Fri, Mar 30, 2012 at 12:16 PM, Thomas Peuss [thomas.peuss@nterra.com](mailto:thomas.peuss@nterra.com)wrote:

> Hi Abhishek!
> 
> Am Freitag, 30. März 2012 06:55:47 UTC+2 schrieb jajoria abhishek:
> 
> > But in this case you have to alter the index mapping and you have to  
> > Index according to queries.
> 
> Exactly. Like in any other NoSQL-DB as well. 😉
> 
> CU  
> Thomas

---

<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, 3:34am UTC](https://discuss.elastic.co/t/no-subject/7171/6 "2017-07-06T03:34:09Z")

</div>


