# How to join 2 indexes at query time

**URL:** <https://discuss.elastic.co/t/how-to-join-2-indexes-at-query-time/16025>\
**Category:** Elasticsearch\
**Created:** [February 26, 2014, 10:44am UTC](https://discuss.elastic.co/t/how-to-join-2-indexes-at-query-time/16025 "2014-02-26T10:44:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsbonline2006](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@jsbonline2006](https://discuss.elastic.co/u/jsbonline2006)\
**Post date:** [February 26, 2014, 10:44am UTC](https://discuss.elastic.co/t/how-to-join-2-indexes-at-query-time/16025/1 "2014-02-26T10:44:04Z")

</div>

Hi All,

I want to join 2 indexes at query time.  
I have created a Gist for this @

> <https://gist.github.com/jsbonline2006/9227299>

I have 2 indexes:

Index 1: offerindex/ Type: offertype  
Index 2: categoryindex/ Type: categorytype

Now as per my index data:  
My input will be category "Flat TV"  
And in output: I want all skuid for "Flat TV" and there corresponding offer\_id.

Regards,  
Jayesh Bhoyar

_GIST @ [https://gist.github.com/jsbonline2006/9227299](https://gist.github.com/jsbonline2006/9227299)_

--  
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/99ad8aa4-dfec-48c1-9605-55c6e3024141%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/99ad8aa4-dfec-48c1-9605-55c6e3024141%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)\
**Post date:** [February 26, 2014, 2:37pm UTC](https://discuss.elastic.co/t/how-to-join-2-indexes-at-query-time/16025/2 "2014-02-26T14:37:01Z")

</div>

Unfortunately, ES is not like SQL in this respect. You'll need to  
denormalize somewhat because ES is more "document-oriented". You'd probably  
need to either denormalize offer\_id into categorytype, or category into  
offertype to get all the data you want returned in 1 query.

--  
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/750f1c19-4eca-4204-9da0-25783feda996%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/750f1c19-4eca-4204-9da0-25783feda996%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jsbonline2006](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@jsbonline2006](https://discuss.elastic.co/u/jsbonline2006)\
**Post date:** [February 27, 2014, 3:45am UTC](https://discuss.elastic.co/t/how-to-join-2-indexes-at-query-time/16025/3 "2014-02-27T03:45:14Z")

</div>

Hi Binh,

Thanks for the answer.

Is there any case if I index this data into same index with different  
category GIST@ [One Index 2 data type join query · GitHub](https://gist.github.com/jsbonline2006/9243973)  
I have 1 index:

productindex/ Type: offertype  
productindex/ Type: categorytype

Now as per my index data:  
My input will be category "Flat TV"  
And in output: I want all skuid for "Flat TV" and there corresponding offer\_id.

Regards,  
Jayesh Bhoyar

_GIST @[One Index 2 data type join query · GitHub](https://gist.github.com/jsbonline2006/9243973)_

On Wednesday, February 26, 2014 8:07:01 PM UTC+5:30, Binh Ly wrote:

> Unfortunately, ES is not like SQL in this respect. You'll need to  
> denormalize somewhat because ES is more "document-oriented". You'd probably  
> need to either denormalize offer\_id into categorytype, or category into  
> offertype to get all the data you want returned in 1 query.

--  
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/bdd1dd5e-be45-4faa-a01f-f6e491249d65%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bdd1dd5e-be45-4faa-a01f-f6e491249d65%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mattweber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattweber/32/44940_2.png) [@mattweber](https://discuss.elastic.co/u/mattweber)\
**Post date:** [February 27, 2014, 4:44am UTC](https://discuss.elastic.co/t/how-to-join-2-indexes-at-query-time/16025/4 "2014-02-27T04:44:09Z")

</div>

How about using parent/child functionality?

> <https://gist.github.com/mattweber/96f3515fc4453a5cb0db>

Thanks,  
Matt Weber

On Wed, Feb 26, 2014 at 7:45 PM, Jayesh Bhoyar [jsbonline2006@gmail.com](mailto:jsbonline2006@gmail.com)wrote:

> Hi Binh,
> 
> Thanks for the answer.
> 
> Is there any case if I index this data into same index with different  
> category GIST@ [One Index 2 data type join query · GitHub](https://gist.github.com/jsbonline2006/9243973)  
> I have 1 index:
> 
> productindex/ Type: offertype  
> productindex/ Type: categorytype
> 
> Now as per my index data:  
> My input will be category "Flat TV"  
> And in output: I want all skuid for "Flat TV" and there corresponding offer\_id.
> 
> Regards,  
> Jayesh Bhoyar
> 
> _GIST @[One Index 2 data type join query · GitHub](https://gist.github.com/jsbonline2006/9243973) [https://gist.github.com/jsbonline2006/9243973](https://gist.github.com/jsbonline2006/9243973)_
> 
> On Wednesday, February 26, 2014 8:07:01 PM UTC+5:30, Binh Ly wrote:
> 
> > Unfortunately, ES is not like SQL in this respect. You'll need to  
> > denormalize somewhat because ES is more "document-oriented". You'd probably  
> > need to either denormalize offer\_id into categorytype, or category into  
> > offertype to get all the data you want returned in 1 query.
> 
> --  
> 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/bdd1dd5e-be45-4faa-a01f-f6e491249d65%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bdd1dd5e-be45-4faa-a01f-f6e491249d65%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/CAJ3KEoCF1hPXeapnrXyPpv3h%3DSetwCPN2MUSV%3DYtNiwW286HWA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAJ3KEoCF1hPXeapnrXyPpv3h%3DSetwCPN2MUSV%3DYtNiwW286HWA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 1:46am UTC](https://discuss.elastic.co/t/how-to-join-2-indexes-at-query-time/16025/5 "2017-07-06T01:46:58Z")

</div>


