Skip to content

Instantly share code, notes, and snippets.

@puttpotsawee
Created September 21, 2018 13:10
Show Gist options
  • Save puttpotsawee/6eaeb6176e04752e780b0d2999c5a6df to your computer and use it in GitHub Desktop.
Save puttpotsawee/6eaeb6176e04752e780b0d2999c5a6df to your computer and use it in GitHub Desktop.
Create Remote Reindex from existing indices
#!/bin/bash
OLD_CLUSTER=localhost:9201
NEW_CLUSTER=localhost:9202
OLD_CLUSTER_SERVICE=logging-elastic-service-old:9200
indices=$(curl $OLD_CLUSTER/_cat/indices | awk '{ print $3 }')
printf "\n\n+++++reindexing those index+++++++\n"
for index in $indices; do
# get your indices prefix, write this regex to grasp your indices but skip .kibana index
if ! [[ $index =~ ^log.*$ ]]; then
continue
fi
printf "\n====Reindexing ${index}====\n"
# run reindexing API
curl -XPOST ${NEW_CLUSTER}/_reindex -H 'content-type: application/json' -d "{\"source\":{\"remote\":{\"host\":\"http://${OLD_CLUSTER_SERVICE}\", \"socket_timeout\": \"10m\", \"connect_timeout\": \"1m\"},\"index\":\"${index}\"},\"dest\":{\"index\":\"${index}\"}}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment