# Joining two indexes

**URL:** https://discuss.elastic.co/t/joining-two-indexes/325876
**Category:** Kibana
**Created:** [February 18, 2023, 2:43am UTC](https://discuss.elastic.co/t/joining-two-indexes/325876 "2023-02-18T02:43:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![etp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/etp/32/117415_2.png) [@etp](https://discuss.elastic.co/u/etp)
#### Post date: [February 18, 2023, 2:43am UTC](https://discuss.elastic.co/t/joining-two-indexes/325876/1 "2023-02-18T02:43:29Z")

</div>

Hi,  
I have two indices A and B. I wanted to perform inner join on the two indices using a common field such that I can collect the fields(spread across both indices) into another index using transforms.

What aggregations would need to be performed to achieve an inner join?

Regards  
Eby

---

<div class="post-metadata">

### Author: ![Wave](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wave/32/117242_2.png) [@Wave](https://discuss.elastic.co/u/Wave)
#### Post date: [February 18, 2023, 3:10pm UTC](https://discuss.elastic.co/t/joining-two-indexes/325876/2 "2023-02-18T15:10:54Z")

</div>

Hi @etp,  
Elasticsearch does provide a [native lightweight structured query language](https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-overview.html). Having said that when trying to run a sql statement with a join you will get the response: "Queries with multiple indices are not supported'.

Other solutions include [nested queries and child/parent queries](https://www.elastic.co/guide/en/elasticsearch/reference/current/joining-queries.html).

All of these options though just work on data in the same index. So [reindexing](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html) both indices into a common index might be needed to achieve what you are looking to do.

Hopefully that gives you a good place to start. Transitioning from a sql mindset to a "no sql" one can be rough, but will a little work you'll find it pays off. 😀 Good luck!

---

<div class="post-metadata">

### Author: ![BenB196](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benb196/32/83401_2.png) [@BenB196](https://discuss.elastic.co/u/BenB196)
#### Post date: [February 19, 2023, 2:57pm UTC](https://discuss.elastic.co/t/joining-two-indexes/325876/3 "2023-02-19T14:57:06Z")

</div>

One possibility is to use something like the [lookup runtime field](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-retrieving-fields.html#lookup-runtime-fields) for this. I created a somewhat pseudo code example [here](https://discuss.elastic.co/t/check-forecast-accuracy-with-scripted-field/324650/4).

---

<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: [March 19, 2023, 2:57pm UTC](https://discuss.elastic.co/t/joining-two-indexes/325876/4 "2023-03-19T14:57:41Z")

</div>

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