# Reindex multiple indices from remote with the same name

**URL:** <https://discuss.elastic.co/t/reindex-multiple-indices-from-remote-with-the-same-name/171674>\
**Category:** Elasticsearch\
**Created:** [March 11, 2019, 6:42am UTC](https://discuss.elastic.co/t/reindex-multiple-indices-from-remote-with-the-same-name/171674 "2019-03-11T06:42:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hokkun-dayo](https://avatars.discourse-cdn.com/v4/letter/h/9d8465/32.png) [@hokkun-dayo](https://discuss.elastic.co/u/hokkun-dayo)\
**Post date:** [March 11, 2019, 6:42am UTC](https://discuss.elastic.co/t/reindex-multiple-indices-from-remote-with-the-same-name/171674/1 "2019-03-11T06:42:33Z")

</div>

I'd like to use Reindex API with remote and create indices with the same name as sources.  
I tried:

```auto
POST _reindex
{
  "source": {
    "remote": {
      "host": "http://myremote:9200"
    },
    "index": "source-*"
  },
  "dest": {
    "index": "source"
  },
  "script": {
    "lang": "painless",
    "source": "ctx._index = 'source-' + (ctx._index.substring('source-'.length(), ctx._index.length()))"
  }
}

```

But it didn't work, just `source` index was created.  
Is there any way to reindex multiple indices with the same index name as original?

---

<div class="post-metadata">

**Author:** ![mjunaidmuzammil](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mjunaidmuzammil/32/56910_2.png) [@mjunaidmuzammil](https://discuss.elastic.co/u/mjunaidmuzammil)\
**Post date:** [March 11, 2019, 7:34am UTC](https://discuss.elastic.co/t/reindex-multiple-indices-from-remote-with-the-same-name/171674/2 "2019-03-11T07:34:54Z")

</div>

The above clearly says to move all the documents from multiple indices matching the wild card criteria to a single index. You will have to reindex selectively with one index at a time. Please refer to the following link for reindexing multiple indices.  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#\_reindexing\_many\_indices](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#_reindexing_many_indices)

---

<div class="post-metadata">

**Author:** ![hokkun-dayo](https://avatars.discourse-cdn.com/v4/letter/h/9d8465/32.png) [@hokkun-dayo](https://discuss.elastic.co/u/hokkun-dayo)\
**Post date:** [March 11, 2019, 7:49am UTC](https://discuss.elastic.co/t/reindex-multiple-indices-from-remote-with-the-same-name/171674/3 "2019-03-11T07:49:35Z")

</div>

Thank you for your reply.

According to [https://www.elastic.co/guide/en/elasticsearch/reference/5.6/docs-reindex.html#\_reindex\_daily\_indices](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/docs-reindex.html#_reindex_daily_indices), if we can change the name of indices, my script will completely work. Why can't we adopt that method?

---

<div class="post-metadata">

**Author:** ![mjunaidmuzammil](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mjunaidmuzammil/32/56910_2.png) [@mjunaidmuzammil](https://discuss.elastic.co/u/mjunaidmuzammil)\
**Post date:** [March 11, 2019, 8:23am UTC](https://discuss.elastic.co/t/reindex-multiple-indices-from-remote-with-the-same-name/171674/4 "2019-03-11T08:23:10Z")

</div>

Hmm, I am not sure about the usage of `ctx` variable over indices that belong to a remote cluster. I would be interested in knowing the details about it as well.

However, as a workaround you can take help of the bash script to achieve your objective.

> <https://gist.github.com/hartfordfive/e507bc47e17f4e03a89055918900e44d>

---

<div class="post-metadata">

**Author:** ![hokkun-dayo](https://avatars.discourse-cdn.com/v4/letter/h/9d8465/32.png) [@hokkun-dayo](https://discuss.elastic.co/u/hokkun-dayo)\
**Post date:** [March 11, 2019, 11:04am UTC](https://discuss.elastic.co/t/reindex-multiple-indices-from-remote-with-the-same-name/171674/5 "2019-03-11T11:04:19Z")

</div>

Your script looks helpful for me 🙂

BTW, I digged into the related parts of Es code base.

> <https://github.com/elastic/elasticsearch/blob/a8596de31fff2372fadd3f48dd97c6d674f2eb58/modules/reindex/src/main/java/org/elasticsearch/index/reindex/AbstractAsyncBulkByScrollAction.java#L785-L787>

Maybe unless the name of new index computed by `script` is different from the original one, a destination won't be changed.  
Anyway, thank you for reply, @mjunaidmuzammil

---

<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:** [April 8, 2019, 11:04am UTC](https://discuss.elastic.co/t/reindex-multiple-indices-from-remote-with-the-same-name/171674/6 "2019-04-08T11:04:22Z")

</div>

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