# Merging two indexes by a column

**URL:** <https://discuss.elastic.co/t/merging-two-indexes-by-a-column/315163>\
**Category:** Kibana\
**Created:** [September 26, 2022, 10:42am UTC](https://discuss.elastic.co/t/merging-two-indexes-by-a-column/315163 "2022-09-26T10:42:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juanfer](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@Juanfer](https://discuss.elastic.co/u/Juanfer)\
**Post date:** [September 26, 2022, 10:42am UTC](https://discuss.elastic.co/t/merging-two-indexes-by-a-column/315163/1 "2022-09-26T10:42:34Z")

</div>

Hello there,

I am a beginner in Elasticsearch and I have been reading about how to merge 2 indexes based on two different names columns with the same values. I understand the NoSQL performance of elastic but still having a hard time performing the queries. For instance I have the following:  
Index\_1: Laptops-id-area

```auto
{
        "_index": "laptops-demo",
        "_id": "1",
        "_score": 1,
        "_source": {
          "id": 1,
          "name": "marketing"
        }
      },
      {
        "_index": "laptops-demo",
        "_id": "2",
        "_score": 1,
        "_source": {
          "id": 2,
          "name": "Finance"
        }
      },
      {
        "_index": "laptops-demo",
        "_id": "3",
        "_score": 1,
        "_source": {
          "id": 3,
          "name": "Sales"
        }

```

Index\_2: laptops

```auto
{
        "_index": "laptops",
        "_id": "1",
        "_score": 1,
        "_source": {
          "id": 1,
          "name": "lenovo",
          "description": "8GB 2022",
          "laptop_id": 3
        }
      },
      {
        "_index": "laptops",
        "_id": "2",
        "_score": 1,
        "_source": {
          "id": 2,
          "name": "Vaio",
          "description": "32GB 2019",
          "laptop_id": 2
        }
      },
      {
        "_index": "laptops",
        "_id": "3",
        "_score": 1,
        "_source": {
          "id": 3,
          "name": "Dell",
          "description": "Intel core i7 64GB 2021",
          "laptop_id": 1
        }

```

Since the fields index\_1.id == index\_2.laptop\_id I would like to output a mapping of the index\_2 fields with the name of index\_1.name. Output:

```auto
"_id", "_score", "name", "description", "laptop_id", "name from index 1"

```

Could you please be so gentle in directing me in the right coding script? Thank you in advance

---

<div class="post-metadata">

**Author:** ![JLeysens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jleysens/32/67404_2.png) [@JLeysens](https://discuss.elastic.co/u/JLeysens)\
**Post date:** [October 5, 2022, 10:27am UTC](https://discuss.elastic.co/t/merging-two-indexes-by-a-column/315163/2 "2022-10-05T10:27:38Z")

</div>

Hello @Juanfer ! I'd recommend reading this docs [Joining queries | Elasticsearch Guide [8.4] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/8.4/joining-queries.html)

You are correct though, full SQL join queries are not supported in Elasticsearch. I'd say think about why you want to separate your data into 2 indices in the first place. Could they not be one?

---

<div class="post-metadata">

**Author:** ![Juanfer](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@Juanfer](https://discuss.elastic.co/u/Juanfer)\
**Post date:** [October 9, 2022, 10:38am UTC](https://discuss.elastic.co/t/merging-two-indexes-by-a-column/315163/3 "2022-10-09T10:38:41Z")

</div>

Hello Jean-Louis, thank you for your replied. I already read the file. We are pulling data from different APIs to Elasticsearch and therefore the different indexes created. I aimed to avoid doing a before step where I merge all the datasets together and after allocating in ES as merging the data in Elasticsearch is the easiest step to make. I am afraid that is not possible and the solution would be to merge the data before allocating in Elastic, am I right?

---

<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:** [November 6, 2022, 10:39am UTC](https://discuss.elastic.co/t/merging-two-indexes-by-a-column/315163/4 "2022-11-06T10:39:06Z")

</div>

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