Skip to content

Instantly share code, notes, and snippets.

@mjameswh
Last active August 18, 2023 20:59
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save mjameswh/59c1f59497c03a5cf3697eeb6ca2445d to your computer and use it in GitHub Desktop.
Save mjameswh/59c1f59497c03a5cf3697eeb6ca2445d 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 .
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