I need to rename several indexes in a cluster (their name must be changed, I cannot use aliases).
I saw that there are no supported ways to do that,
For renaming your index you can use Elasticsearch Snapshot module.
First you have to take 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 :-New indexname in which you want backup your data.
Another different way to achieve the renaming or change the mappings for an index is to reindex using logstash. Here is a sample of the 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"
}
}
Just in case someone still needs it. The successful, not official, way to rename indexes are:
If you happen to get this error "dangled index directory name is", remove index folder in all master nodes (not data nodes), and restart one of the data nodes.
If you can't REINDEX a workaround is to use aliases. From the official documentation:
APIs in elasticsearch accept an index name when working against a specific index, and several indices when applicable. The index aliases API allow to alias 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 specifying it, the alias will automatically expand to the aliases indices. An alias can also be associated with a filter that will automatically be applied when searching, and routing values. An alias cannot have the same name as an index.
Be aware that this solution does not work if you're using More Like This feature. https://github.com/elastic/elasticsearch/issues/16560
As indicated in Elasticsearch reference for snapshot module,
The rename_pattern and rename_replacement options can be also used to rename index on restore using regular expression
You can use REINDEX to do that.
Reindex does not attempt to set up the destination index. It does not copy the settings of the source index. You should set up the destination index prior to running a _reindex action, including setting up mappings, shard counts, replicas, etc.
POST /_reindex
{
"source": {
"index": "twitter"
},
"dest": {
"index": "new_twitter"
}
}
DELETE /twitter