# Merging document \_source from 2 indices to a 3rd index

**URL:** <https://discuss.elastic.co/t/merging-document-source-from-2-indices-to-a-3rd-index/119365>\
**Category:** Elasticsearch\
**Created:** [February 11, 2018, 5:08am UTC](https://discuss.elastic.co/t/merging-document-source-from-2-indices-to-a-3rd-index/119365 "2018-02-11T05:08:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ehtishamkhan](https://avatars.discourse-cdn.com/v4/letter/e/ed8c4c/32.png) [@ehtishamkhan](https://discuss.elastic.co/u/ehtishamkhan)\
**Post date:** [February 11, 2018, 5:08am UTC](https://discuss.elastic.co/t/merging-document-source-from-2-indices-to-a-3rd-index/119365/1 "2018-02-11T05:08:23Z")

</div>

I have a couple of indices with the following document structure.

Index 1  
"\_source": {  
"guid": "abc123",  
"documentdescription": "document description",  
}

Index 2  
"\_source": {  
"guid": "abc123",  
"documenttitle": "document title",  
}

I want to create a 3rd index by with \_source with merged attributes on guid.

Index 3  
"\_source": {  
"guid": "abc123",  
"documentdescription": "document description",  
"documenttitle": "document title",  
}

I have explored logstash ingestion to create a new index (Index 3) however was not able to figure out a technique to accomplish this. Trying to avoid writing a full blown client program to loop over all documents in both indices 🙂

---

<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:** [February 11, 2018, 5:43am UTC](https://discuss.elastic.co/t/merging-document-source-from-2-indices-to-a-3rd-index/119365/2 "2018-02-11T05:43:39Z")

</div>

With logstash, I believe you can use elasticsearch-input plugin to read all the docs from index 1 then elasticsearch-filter plugin to do lookups in index 2 and elasticsearch-output plugin to write to index 3.

---

<div class="post-metadata">

**Author:** ![ehtishamkhan](https://avatars.discourse-cdn.com/v4/letter/e/ed8c4c/32.png) [@ehtishamkhan](https://discuss.elastic.co/u/ehtishamkhan)\
**Post date:** [February 11, 2018, 6:29am UTC](https://discuss.elastic.co/t/merging-document-source-from-2-indices-to-a-3rd-index/119365/3 "2018-02-11T06:29:34Z")

</div>

Thanks David, Some sample code will be a huge 🙂

---

<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 11, 2018, 6:29am UTC](https://discuss.elastic.co/t/merging-document-source-from-2-indices-to-a-3rd-index/119365/4 "2018-03-11T06:29:45Z")

</div>

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

---

<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:** [April 13, 2018, 1:18pm UTC](https://discuss.elastic.co/t/merging-document-source-from-2-indices-to-a-3rd-index/119365/5 "2018-04-13T13:18:13Z")

</div>



---

<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:** [April 13, 2018, 1:32pm UTC](https://discuss.elastic.co/t/merging-document-source-from-2-indices-to-a-3rd-index/119365/6 "2018-04-13T13:32:57Z")

</div>

I'm sorry it took so long but here is in short what you can do:

```auto
input {
  elasticsearch {
    index => "index1"
  }
}

filter {
  elasticsearch {
    index => "index2"
    query => "guid:%{[guid]}"
    fields => {
      "documenttitle" => "[documenttitle]"
    }
  }
}

output {
  elasticsearch {
    index => "index3"
  }
}

```

Something along those lines. I did not test it though.

Hope this helps.

---

<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 4, 2022, 5:13am UTC](https://discuss.elastic.co/t/merging-document-source-from-2-indices-to-a-3rd-index/119365/7 "2022-11-04T05:13:35Z")

</div>


