Last active
August 2, 2016 19:59
-
-
Save tomwalsh/80b52018f6b82ed9732a84dabed17ec6 to your computer and use it in GitHub Desktop.
This is a simple script that will run against a local elasticsearch instance and search for one index name and rename it to another index name. rename-indexes.sh oldname newname
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
#!/bin/bash | |
for i in `/usr/bin/curl -s 'http://localhost:9200/_cat/indices?v' 2>&1 | grep $1 | awk '{print $3}'` | |
do | |
echo "Starting on $i" | |
NEWFILE=$( echo $i | sed "s/$1-/$2-/") | |
echo -n "Converting $i to $NEWFILE ..." | |
STATUSCODE=$(/usr/bin/curl -o /dev/null -s --write-out "%{http_code}" -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d "{\"source\":{\"index\":\"$i\"},\"dest\":{\"index\":\"$NEWFILE\"}}" http://localhost:9200/_reindex ) | |
if test $STATUSCODE -eq 200; then | |
echo " done." | |
echo -n "Deleting $i..." | |
RETURNCODE=$(/usr/bin/curl -o /dev/null -s --write-out "%{http_code}" -i -X DELETE http://localhost:9200/$i) | |
if test $RETURNCODE -eq 200; then | |
echo " done." | |
else | |
echo " failed." | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment