-
-
Save druman/924fdd1c4f99a426906603f10e746f3a to your computer and use it in GitHub Desktop.
Demonstration of how to rename an ElasticSearch index using the Index Clone API, introduced in ES 7.4. This is the cUrl based version. See here for details: https://stackoverflow.com/a/59397746/2887657 .
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source_index=source_index | |
target_index=target_index | |
elastic_search_server=elasticsearch:9200 | |
# Make sure the source index is actually open | |
curl -X POST "${elastic_search_server}/${source_index}/_open" | |
# Put the source index in read-only mode | |
curl -X PUT "${elastic_search_server}/${source_index}/_settings" \ | |
-H 'Content-Type: application/json' -d'{ | |
"settings": { | |
"index.blocks.write": "true" | |
} | |
}' | |
# Clone the source index to the target name, and set the target to read-write mode | |
curl -X POST "${elastic_search_server}/${source_index}/_clone/${target_index}" \ | |
-H 'Content-Type: application/json' -d'{ | |
"settings": { | |
"index.blocks.write": null | |
} | |
}' | |
# Wait until the target index is green; | |
# it should usually be fast (assuming your filesystem supports hard links). | |
curl -X GET "${elastic_search_server}/_cluster/health/${target_index}?wait_for_status=green&timeout=30s" | |
# If it appears to be taking too much time for the cluster to get back to green, | |
# the following requests might help you identify eventual outstanding issues (if any) | |
curl -X GET "${elastic_search_server}/_cat/indices/${target_index}" | |
curl -X GET "${elastic_search_server}/_cat/recovery/${target_index}" | |
curl -X GET "${elastic_search_server}/_cluster/allocation/explain" | |
# Delete the source index | |
curl -X DELETE "${elastic_search_server}/${source_index}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment