How to rename an index in a cluster?

I need to rename several indexes in a cluster (their name needs to be changed, I cannot use aliases ).

I saw that there are no supported ways to do this, the closest I found to rename the index directory , I tried this in a cluster.

There are 3 machines A , B and C in the cluster, and the fragments are replicated on each of them. I disabled elasticsearch on A , renamed /var/lib/elasticsearch/security/nodes/0/indices/oldindexname to /var/lib/elasticsearch/security/nodes/0/indices/newindexname and restarted A

The cluster state was yellow, and elasticsearch did the magic to restore the correct state. After a while I ended up with

  • oldindexname is accessible and fully replicated (restored from B and C , I think)
  • newindexname is available (I can search for it), but the head plugin shows that its fragments are in the โ€œUnassignedโ€ state and that they are inactive (not replicated).

During security.log recovery, the following message appeared:

 [2015-02-20 11:02:33,461][INFO ][gateway.local.state.meta ] [A.example.com] dangled index directory name is [newindexname], state name is [oldindexname], renaming to directory name 

While newindexname is searchable, it is, of course, not in a normal state.

I returned to my previous state by deleting newindexname . The cluster returns to green without any โ€œunassignedโ€ entries.

Given this, how can I rename oldindexname to newindexname in the cluster?

Note. The final solution that I have in mind is to scroll-copy oldindex into newindex and delete oldindex afterwards. It will take some time, so if there was a more direct solution, it would be great.

+100
elasticsearch
Feb 20 '15 at 10:32
source share
8 answers

You can use the Elasticsearch snapshot module to rename the index.

First you need to take a snapshot of your index.while, restoring it, you can rename your index.

  POST /_snapshot/my_backup/snapshot_1/_restore { "indices": "jal", "ignore_unavailable": "true", "include_global_state": false, "rename_pattern": "jal", "rename_replacement": "jal1" } 

rename_replacement: -The new index name in which you want to backup your data.

+50
Feb 24 '16 at 5:00
source share

You can use REINDEX to do this.

Reindex is not trying to configure the destination index. This does not copy the settings of the source index. You must configure the destination index before starting the _reindex action, including setting up mappings, counting shards, replicas, etc.

  • First copy the index into the new name
 POST /_reindex { "source": { "index": "twitter" }, "dest": { "index": "new_twitter" } } 
  1. Now delete the index
 DELETE /twitter 
+149
Jun 28 '16 at 13:49
source share

If you cannot use REINDEX, the workaround is to use aliases. From the official documentation:

The elasticsearch APIs accept the index name when working with a specific index, and multiple indexes, if applicable. The index alias API allows you to pseudonize an index with a name, with all APIs automatically converting the alias name to the actual index name. An alias can also be mapped to more than one index, and when it is defined, the alias will automatically expand to the alias index. An alias can also be associated with a filter that will be automatically applied when searching and routing values. An alias cannot have the same name as an index.

Remember that this solution does not work if you use the "More Like This" function. https://github.com/elastic/elasticsearch/issues/16560

+6
Sep 19 '16 at 8:38
source share

As such there is no direct method for copying or renaming an index in ES (I have extensively searched for my project)

However, a very simple option is to use the popular migration tool [Elastic-Exporter].

http://www.retailmenot.com/corp/eng/posts/2014/12/02/elasticsearch-cluster-migration/

[PS: this is not my blog, just stumbled and found it good)

This way you can copy the index / type and then delete the old one.

+5
Jun 30 '15 at 19:59
source share

Another other way to achieve renaming or changing mappings for an index is to reindex using logstash. Here is an example logstash 2.1 configuration:

 input { elasticsearch { hosts => ["es01.example.com", "es02.example.com"] index => "old-index-name" size => 500 scroll => "5m" } } filter { mutate { remove_field => [ "@version" ] } date { "match" => [ "custom_timestamp", "MM/dd/YYYY HH:mm:ss" ] target => "@timestamp" } } output { elasticsearch { hosts => ["es01.example.com", "es02.example.com" ] manage_template => false index => "new-index-name" } } 
+5
Dec 16 '15 at 17:20
source share

As stated in the Elasticearch link for the snapshot module ,

The rename_pattern and rename_replacement options can also be used to rename an index during recovery using a regular expression

+3
Jan 12 '16 at 13:10
source share

The following command worked for me:

 POST /_aliases { "actions": [ { "add": { "index": "new_index", "alias": "old_index" } }, { "remove_index": { "index": "old_index" } } ] } 
-one
Aug 13 '19 at 2:06
source share

Just in case, someone still needs it. A successful rather than official way to rename indexes:

  • Close indexes to rename
  • Rename index folders to all data directories of master nodes and data nodes.
  • Reopen old private indexes (I use the kofp plugin). Old indexes will be reopened, but remain unassigned. New indexes will appear in a closed state
  • Reopen New Indexes
  • Delete old indexes

If you are fortunate enough to receive this error, "a directory name with a blurred index," delete the index folder in all the main nodes (not the data nodes) and restart one of the data nodes.

-5
Jul 21 '16 at 20:27
source share



All Articles