# How to join two index

**URL:** <https://discuss.elastic.co/t/how-to-join-two-index/57377>\
**Category:** Elasticsearch\
**Created:** [August 5, 2016, 4:53pm UTC](https://discuss.elastic.co/t/how-to-join-two-index/57377 "2016-08-05T16:53:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![spraveenjd](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@spraveenjd](https://discuss.elastic.co/u/spraveenjd)\
**Post date:** [August 5, 2016, 4:53pm UTC](https://discuss.elastic.co/t/how-to-join-two-index/57377/1 "2016-08-05T16:53:30Z")

</div>

I have two index, I want to join them both. How to do that?  
for Ex: Emp is an one index with department id  
Department is other index with details and index id as department id.

I want to join both index with department id

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [August 5, 2016, 5:14pm UTC](https://discuss.elastic.co/t/how-to-join-two-index/57377/2 "2016-08-05T17:14:40Z")

</div>

Hi spraveenjd,

Elasticsearch can not joins indices. At most you can either use parent/child or nested object mappings, but you are limited to one index only. Please refer to [https://www.elastic.co/guide/en/elasticsearch/guide/2.x/relations.html](https://www.elastic.co/guide/en/elasticsearch/guide/2.x/relations.html) for more information.

If you decide to do application side joining and you have a large dataset then you could use Apache Spark using the es-hadoop integration ([https://www.elastic.co/products/hadoop](https://www.elastic.co/products/hadoop)).

Best regards

---

<div class="post-metadata">

**Author:** ![spraveenjd](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@spraveenjd](https://discuss.elastic.co/u/spraveenjd)\
**Post date:** [August 5, 2016, 6:03pm UTC](https://discuss.elastic.co/t/how-to-join-two-index/57377/3 "2016-08-05T18:03:09Z")

</div>

> [@Thiago\_Souza](#):
>
> have a large datas

Thanks Thiago  
Is there a possibility to create the parent and child relation in logstash? If so please help me with a sample.

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [August 5, 2016, 6:08pm UTC](https://discuss.elastic.co/t/how-to-join-two-index/57377/4 "2016-08-05T18:08:50Z")

</div>

if you are talking about how to instruct logstash to create a mapping that uses parent/child, then you just need to create the appropriate index template mapping that you want to use and configure the logstash elasticsearch output to use it (refer to [https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-template](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-template))

---

<div class="post-metadata">

**Author:** ![QD\_Wang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/qd_wang/32/8409_2.png) [@QD\_Wang](https://discuss.elastic.co/u/QD_Wang)\
**Post date:** [August 5, 2016, 6:34pm UTC](https://discuss.elastic.co/t/how-to-join-two-index/57377/5 "2016-08-05T18:34:33Z")

</div>

[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html)

instead of join ,we use terms query.

---

<div class="post-metadata">

**Author:** ![thiago](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thiago/32/32096_2.png) [@thiago](https://discuss.elastic.co/u/thiago)\
**Post date:** [August 5, 2016, 7:14pm UTC](https://discuss.elastic.co/t/how-to-join-two-index/57377/6 "2016-08-05T19:14:37Z")

</div>

Hello QD\_Wang,

Maybe you could describe a little bit more of your problem?

I don't see how terms query could be a replacement for joins...

---

<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 5, 2017, 10:29pm UTC](https://discuss.elastic.co/t/how-to-join-two-index/57377/7 "2017-07-05T22:29:41Z")

</div>


