# Merge two indexes to one

**URL:** <https://discuss.elastic.co/t/merge-two-indexes-to-one/342585>\
**Category:** Elasticsearch\
**Created:** [September 8, 2023, 7:57am UTC](https://discuss.elastic.co/t/merge-two-indexes-to-one/342585 "2023-09-08T07:57:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neelam\_Zanvar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/neelam_zanvar/32/103116_2.png) [@Neelam\_Zanvar](https://discuss.elastic.co/u/Neelam_Zanvar)\
**Post date:** [September 8, 2023, 7:57am UTC](https://discuss.elastic.co/t/merge-two-indexes-to-one/342585/1 "2023-09-08T07:57:44Z")

</div>

Hi i would like to merge two indexes to one index, with same fields except for one field.  
i tried the reindex api but it is not working with regular expressions in the indexname. my index has timestamp attached to it. so i want index1-timestamp1 and index2-timestamp1 to be mergeed to index3-timestamp3. How can i do that?

---

<div class="post-metadata">

**Author:** ![mostafaelsayed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mostafaelsayed/32/82057_2.png) [@mostafaelsayed](https://discuss.elastic.co/u/mostafaelsayed)\
**Post date:** [September 9, 2023, 10:15am UTC](https://discuss.elastic.co/t/merge-two-indexes-to-one/342585/2 "2023-09-09T10:15:22Z")

</div>

Not Sure if it will help your use case  
but have a look at this  
[Reindex daily indices](https://www.elastic.co/guide/en/elasticsearch/reference/7.9/docs-reindex.html#docs-reindex-daily-indices)

---

<div class="post-metadata">

**Author:** ![Samuele\_Lolli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/samuele_lolli/32/107848_2.png) [@Samuele\_Lolli](https://discuss.elastic.co/u/Samuele_Lolli)\
**Post date:** [September 11, 2023, 6:30am UTC](https://discuss.elastic.co/t/merge-two-indexes-to-one/342585/3 "2023-09-11T06:30:32Z")

</div>

Hi @Neelam_Zanvar,  
maybe you can create a logstash pipeline that take in input the index you want to merge and in output the final index.

Let me know if that can work

---

<div class="post-metadata">

**Author:** ![Neelam\_Zanvar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/neelam_zanvar/32/103116_2.png) [@Neelam\_Zanvar](https://discuss.elastic.co/u/Neelam_Zanvar)\
**Post date:** [September 11, 2023, 6:41am UTC](https://discuss.elastic.co/t/merge-two-indexes-to-one/342585/4 "2023-09-11T06:41:38Z")

</div>

can i get a sample for the same?

---

<div class="post-metadata">

**Author:** ![Samuele\_Lolli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/samuele_lolli/32/107848_2.png) [@Samuele\_Lolli](https://discuss.elastic.co/u/Samuele_Lolli)\
**Post date:** [September 11, 2023, 6:57am UTC](https://discuss.elastic.co/t/merge-two-indexes-to-one/342585/5 "2023-09-11T06:57:45Z")

</div>

Maybe something like that:

```auto
input {
  elasticsearch {
    hosts => "localhost"
    query => '{ "query": { "match": { "statuscode": 200 } }, "sort": ["_doc"] }'
  }
  elasticsearch {
    hosts => "localhost"
    query => '{ "query": { "match": { "statuscode": 200 } }, "sort": ["_doc"] }'
  }
}
output {
  elasticsearch {
  hosts => "hostname"
  data_stream => "true"
  }
}

```

---

<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:** [October 9, 2023, 6:58am UTC](https://discuss.elastic.co/t/merge-two-indexes-to-one/342585/6 "2023-10-09T06:58:02Z")

</div>

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