# Joining Two Indexes with common field values

**URL:** <https://discuss.elastic.co/t/joining-two-indexes-with-common-field-values/332861>\
**Category:** Elasticsearch\
**Created:** [May 9, 2023, 4:19am UTC](https://discuss.elastic.co/t/joining-two-indexes-with-common-field-values/332861 "2023-05-09T04:19:54Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![sai\_ravi\_shankar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sai_ravi_shankar/32/120767_2.png) [@sai\_ravi\_shankar](https://discuss.elastic.co/u/sai_ravi_shankar)\
**Post date:** [May 9, 2023, 4:19am UTC](https://discuss.elastic.co/t/joining-two-indexes-with-common-field-values/332861/1 "2023-05-09T04:19:54Z")

</div>

Hi,

I am trying to join two indexes with common field values. Can someone please help me.

Here is the example:

Index\_1 =\> A  
column\_1 =\> value\_1

Index\_2 =\> B  
column\_2 =\> value\_1

How can i join both indexes on the match of value\_1?

Thanks in Advance

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 9, 2023, 5:10am UTC](https://discuss.elastic.co/t/joining-two-indexes-with-common-field-values/332861/2 "2023-05-09T05:10:45Z")

</div>

Elasticsearch does not support joins so what you are trying to do is not possible. You will therefore need to change how you index and structure your data. If you can provide some details about your data and the problem you are trying to solve the community might be able to help.

---

<div class="post-metadata">

**Author:** ![sai\_ravi\_shankar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sai_ravi_shankar/32/120767_2.png) [@sai\_ravi\_shankar](https://discuss.elastic.co/u/sai_ravi_shankar)\
**Post date:** [May 9, 2023, 10:21am UTC](https://discuss.elastic.co/t/joining-two-indexes-with-common-field-values/332861/3 "2023-05-09T10:21:35Z")

</div>

Hi,

I am taking data from 2 csv files and getting indexed into ES. My requirement is I need to create a bar graph when the specific field value matches with the another field value of other index.

In Sql, usually it possible through inner and outer join queries. I am expecting same in elasticsearch as well.

please share some suggestions.

Thanks

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 9, 2023, 10:33am UTC](https://discuss.elastic.co/t/joining-two-indexes-with-common-field-values/332861/4 "2023-05-09T10:33:51Z")

</div>

> [@sai\_ravi\_shankar](#):
>
> In Sql, usually it possible through inner and outer join queries. I am expecting same in elasticsearch as well.

Elasticsearch is not a relational database and does not support joins.

I would recommend you denormalise and perform the join ahead of indexing the data, e.g. using an [ingest pipeline](https://www.elastic.co/guide/en/elasticsearch/reference/8.7/ingest.html) with an [enrich processor](https://www.elastic.co/guide/en/elasticsearch/reference/8.7/enrich-processor.html).

---

<div class="post-metadata">

**Author:** ![martel](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@martel](https://discuss.elastic.co/u/martel)\
**Post date:** [May 9, 2023, 10:39am UTC](https://discuss.elastic.co/t/joining-two-indexes-with-common-field-values/332861/5 "2023-05-09T10:39:12Z")

</div>

but it is possible to do than inner join.  
if you do a request with only "value\_1", you see only all row in your 2 index no ?  
a dashboard with table and request with a "WHERE" "value\_1" ?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 9, 2023, 10:42am UTC](https://discuss.elastic.co/t/joining-two-indexes-with-common-field-values/332861/6 "2023-05-09T10:42:39Z")

</div>

> [@martel](#):
>
> but it is possible to do than inner join.  
> if you do a request with only "value\_1", you see only all row in your 2 index no ?  
> a dashboard with table and request with a "WHERE" "value\_1" ?

I do not understand what you mean. Can you please elaborate?

---

<div class="post-metadata">

**Author:** ![martel](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@martel](https://discuss.elastic.co/u/martel)\
**Post date:** [May 9, 2023, 11:21am UTC](https://discuss.elastic.co/t/joining-two-indexes-with-common-field-values/332861/7 "2023-05-09T11:21:12Z")

</div>

ok.

My way of doing it is a little twisted but comes from my experience in managing data files.  
imagine you have 3 tables.  
Table\_A and Table\_B and Table\_C  
then in each of the ID tables.

I concatenate the table name with its id for each table.  
In your table A you will have an additional column that looks like this:  
"Table\_A 54687561615 Table\_B 7445123214"  
"Table\_A 54687561615 Table\_B 7445123215"  
"Table\_A 54687561615 Table\_B 7445123216"

Table B: (here it is you need bidirectional query)  
"Table\_B 7445123214 Table\_A 54687561615  
"Table\_B 7445123215 Table\_A 54687561615  
"Table\_B 7445123215 Table\_C 1615  
"Table\_B 7445123216 Table\_A 54687561615  
"Table\_B 8575123244 Table\_C 1615

Table C:  
"Table\_C 1615 Table\_B 7445123215"  
"Table\_C 1615 Table\_B 8575123244"

this column is a character string which will have the name of the table SPACE its id SPACE name of the table 2 SPACE its id

if you search on an ID, as this field in Elasticsearch is (must) be a text, its search method is of type phrase. i.e. each space is not considered as an indexing character.  
a search for "Table\_C 1615" will return the rows from table B and C that match:  
"Table\_B 7445123215 Table\_C 1615"  
"Table\_B 8575123244 Table\_C 1615"  
"Table\_C 1615 Table\_B 7445123215"  
"Table\_C 1615 Table\_B 8575123244"

which corresponds to a somewhat crude innerjoin but you do have all the information of your 4 elements 2 in table B and 2 in table C.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 11, 2023, 12:50am UTC](https://discuss.elastic.co/t/joining-two-indexes-with-common-field-values/332861/8 "2023-05-11T00:50:37Z")

</div>

Are you saying you put all of these "tables" into a single index in Elasticsearch?

---

<div class="post-metadata">

**Author:** ![sai\_ravi\_shankar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sai_ravi_shankar/32/120767_2.png) [@sai\_ravi\_shankar](https://discuss.elastic.co/u/sai_ravi_shankar)\
**Post date:** [May 11, 2023, 2:22pm UTC](https://discuss.elastic.co/t/joining-two-indexes-with-common-field-values/332861/9 "2023-05-11T14:22:30Z")

</div>

> [@warkolm](#):
>
> ou put all of these "tables" into a single

Yes, on the match of value\_1.

---

<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:** [June 8, 2023, 2:23pm UTC](https://discuss.elastic.co/t/joining-two-indexes-with-common-field-values/332861/10 "2023-06-08T14:23:29Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
