# How to "join" select with two indces?

**URL:** <https://discuss.elastic.co/t/how-to-join-select-with-two-indces/8471>\
**Category:** Elasticsearch\
**Created:** [July 19, 2012, 10:33pm UTC](https://discuss.elastic.co/t/how-to-join-select-with-two-indces/8471 "2012-07-19T22:33:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yuhan](https://avatars.discourse-cdn.com/v4/letter/y/919ad9/32.png) [@Yuhan](https://discuss.elastic.co/u/Yuhan)\
**Post date:** [July 19, 2012, 10:33pm UTC](https://discuss.elastic.co/t/how-to-join-select-with-two-indces/8471/1 "2012-07-19T22:33:48Z")

</div>

Hi all,

I'd like to perform a join search between two indices. Is this doable in  
elasticsearch?

Thank you.

Yuhan

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 19, 2012, 10:38pm UTC](https://discuss.elastic.co/t/how-to-join-select-with-two-indces/8471/2 "2012-07-19T22:38:22Z")

</div>

Search in all indices or with index1,index2/\_search

HTH  
David

--

Le 20 juil. 2012 à 00:33, Yuhan Zhang [yzhang@onescreen.com](mailto:yzhang@onescreen.com) a écrit :

> Hi all,
> 
> I'd like to perform a join search between two indices. Is this doable in elasticsearch?
> 
> Thank you.
> 
> Yuhan

---

<div class="post-metadata">

**Author:** ![Yuhan](https://avatars.discourse-cdn.com/v4/letter/y/919ad9/32.png) [@Yuhan](https://discuss.elastic.co/u/Yuhan)\
**Post date:** [July 19, 2012, 11:46pm UTC](https://discuss.elastic.co/t/how-to-join-select-with-two-indces/8471/3 "2012-07-19T23:46:06Z")

</div>

Hi David,

a question about the query: in case of that index1 and index2 both have doc  
id=1, will this query return 2 docs with id=1 or 1 doc with id=1 with  
fields from both? ... I guess I have to make some experiments. thanks for  
the answer. it is helpful.

Thank you.

Yuhan

On Thu, Jul 19, 2012 at 3:38 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Search in all indices or with index1,index2/\_search
> 
> HTH  
> David
> 
> --
> 
> Le 20 juil. 2012 à 00:33, Yuhan Zhang [yzhang@onescreen.com](mailto:yzhang@onescreen.com) a écrit :
> 
> > Hi all,
> > 
> > I'd like to perform a join search between two indices. Is this doable in  
> > elasticsearch?
> > 
> > Thank you.
> > 
> > Yuhan

--  
Yuhan Zhang  
Senior Software Engineer  
OneScreen Inc.  
[yzhang@onescreen.com](mailto:yzhang@onescreen.com) [ehorne@onescreen.com](mailto:ehorne@onescreen.com)  
[www.onescreen.com](http://www.onescreen.com)

The information contained in this e-mail is for the exclusive use of the  
intended recipient(s) and may be confidential, proprietary, and/or legally  
privileged. Inadvertent disclosure of this message does not constitute a  
waiver of any privilege. If you receive this message in error, please do  
not directly or indirectly print, copy, retransmit, disseminate, or  
otherwise use the information. In addition, please delete this e-mail and  
all copies and notify the sender.

---

<div class="post-metadata">

**Author:** ![Yuhan](https://avatars.discourse-cdn.com/v4/letter/y/919ad9/32.png) [@Yuhan](https://discuss.elastic.co/u/Yuhan)\
**Post date:** [July 20, 2012, 12:02am UTC](https://discuss.elastic.co/t/how-to-join-select-with-two-indces/8471/4 "2012-07-20T00:02:04Z")

</div>

hmm, looks like it returns 2 docs on from each index. I'd like to perform  
something similar to join in sql to find docs with same that have contains  
different terms in different indices... looks like they have to be in the  
same doc in case of using elasticsearch.

Thanks for the help.

Yuhan

On Thu, Jul 19, 2012 at 4:46 PM, Yuhan Zhang [yzhang@onescreen.com](mailto:yzhang@onescreen.com) wrote:

> Hi David,
> 
> a question about the query: in case of that index1 and index2 both have  
> doc id=1, will this query return 2 docs with id=1 or 1 doc with id=1 with  
> fields from both? ... I guess I have to make some experiments. thanks for  
> the answer. it is helpful.
> 
> Thank you.
> 
> Yuhan
> 
> On Thu, Jul 19, 2012 at 3:38 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> 
> > Search in all indices or with index1,index2/\_search
> > 
> > HTH  
> > David
> > 
> > --
> > 
> > Le 20 juil. 2012 à 00:33, Yuhan Zhang [yzhang@onescreen.com](mailto:yzhang@onescreen.com) a écrit :
> > 
> > > Hi all,
> > > 
> > > I'd like to perform a join search between two indices. Is this doable  
> > > in elasticsearch?
> > > 
> > > Thank you.
> > > 
> > > Yuhan
> 
> --  
> Yuhan Zhang  
> Senior Software Engineer  
> OneScreen Inc.  
> [yzhang@onescreen.com](mailto:yzhang@onescreen.com) [ehorne@onescreen.com](mailto:ehorne@onescreen.com)  
> [www.onescreen.com](http://www.onescreen.com)
> 
> The information contained in this e-mail is for the exclusive use of the  
> intended recipient(s) and may be confidential, proprietary, and/or legally  
> privileged. Inadvertent disclosure of this message does not constitute a  
> waiver of any privilege. If you receive this message in error, please do  
> not directly or indirectly print, copy, retransmit, disseminate, or  
> otherwise use the information. In addition, please delete this e-mail and  
> all copies and notify the sender.

--  
Yuhan Zhang  
Senior Software Engineer  
OneScreen Inc.  
[yzhang@onescreen.com](mailto:yzhang@onescreen.com) [ehorne@onescreen.com](mailto:ehorne@onescreen.com)  
[www.onescreen.com](http://www.onescreen.com)

The information contained in this e-mail is for the exclusive use of the  
intended recipient(s) and may be confidential, proprietary, and/or legally  
privileged. Inadvertent disclosure of this message does not constitute a  
waiver of any privilege. If you receive this message in error, please do  
not directly or indirectly print, copy, retransmit, disseminate, or  
otherwise use the information. In addition, please delete this e-mail and  
all copies and notify the sender.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 20, 2012, 6:01am UTC](https://discuss.elastic.co/t/how-to-join-select-with-two-indces/8471/5 "2012-07-20T06:01:25Z")

</div>

For Elasticsearch, a document is unique with its coordinates :  
\_index  
\_type  
\_id

So, you will get back two different documents even if content is exactly the same.

Can you illustrate your use case with an example?

Why do you have the same document in two index? Why do you have two index?

## David

Le 20 juil. 2012 à 02:02, Yuhan Zhang [yzhang@onescreen.com](mailto:yzhang@onescreen.com) a écrit :

> hmm, looks like it returns 2 docs on from each index. I'd like to perform something similar to join in sql to find docs with same that have contains different terms in different indices... looks like they have to be in the same doc in case of using elasticsearch.
> 
> Thanks for the help.
> 
> Yuhan
> 
> On Thu, Jul 19, 2012 at 4:46 PM, Yuhan Zhang [yzhang@onescreen.com](mailto:yzhang@onescreen.com) wrote:  
> Hi David,
> 
> a question about the query: in case of that index1 and index2 both have doc id=1, will this query return 2 docs with id=1 or 1 doc with id=1 with fields from both? ... I guess I have to make some experiments. thanks for the answer. it is helpful.
> 
> Thank you.
> 
> Yuhan
> 
> On Thu, Jul 19, 2012 at 3:38 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:  
> Search in all indices or with index1,index2/\_search
> 
> HTH  
> David
> 
> --
> 
> Le 20 juil. 2012 à 00:33, Yuhan Zhang [yzhang@onescreen.com](mailto:yzhang@onescreen.com) a écrit :
> 
> > Hi all,
> > 
> > I'd like to perform a join search between two indices. Is this doable in elasticsearch?
> > 
> > Thank you.
> > 
> > Yuhan
> 
> --  
> Yuhan Zhang  
> Senior Software Engineer  
> OneScreen Inc.  
> [yzhang@onescreen.com](mailto:yzhang@onescreen.com)  
> [www.onescreen.com](http://www.onescreen.com)
> 
> The information contained in this e-mail is for the exclusive use of the intended recipient(s) and may be confidential, proprietary, and/or legally privileged. Inadvertent disclosure of this message does not constitute a waiver of any privilege. If you receive this message in error, please do not directly or indirectly print, copy, retransmit, disseminate, or otherwise use the information. In addition, please delete this e-mail and all copies and notify the sender.
> 
> --  
> Yuhan Zhang  
> Senior Software Engineer  
> OneScreen Inc.  
> [yzhang@onescreen.com](mailto:yzhang@onescreen.com)  
> [www.onescreen.com](http://www.onescreen.com)
> 
> The information contained in this e-mail is for the exclusive use of the intended recipient(s) and may be confidential, proprietary, and/or legally privileged. Inadvertent disclosure of this message does not constitute a waiver of any privilege. If you receive this message in error, please do not directly or indirectly print, copy, retransmit, disseminate, or otherwise use the information. In addition, please delete this e-mail and all copies and notify the sender.

---

<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:19am UTC](https://discuss.elastic.co/t/how-to-join-select-with-two-indces/8471/6 "2017-07-06T03:19:44Z")

</div>


