Reindex multiple indices from remote with the same name

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

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?

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

Thank you for your reply.

According to 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?

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.

1 Like

Your script looks helpful for me :slight_smile:

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

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

1 Like

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