Created
April 3, 2019 11:02
-
-
Save karlbaillie/22c699e6e95d449807f2250d966730f9 to your computer and use it in GitHub Desktop.
Reindex ElasticSearch one index at a time using ElasticDump.
This file contains hidden or 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 | |
# REQUIRES: | |
# elasticdump, gzip, curl | |
# BE CAREFUL OF: | |
# the check before it'll delete the index it's just dumped it to just see if it's | |
# larger than a gzip file with no content (21 bytes), more thorough checking may be required depending | |
# on importance and availability of your data | |
for i in $(curl -s http://elasticsearch:9200/_cat/indices?pretty | awk '{print $3}'); do | |
printf "dumping index '$i'... " | |
elasticdump --quiet --input=http://elasticsearch:9200/$i --output=$ | gzip > $i.json.gz | |
printf "done!\n" | |
dumpsize=$(wc -c <$i.json.gz) | |
minimumsize=21 | |
if [ $dumpsize -gt 21 ]; then | |
printf "deleting index '$i'... " | |
curl -s -x DELETE http://elasticsearch:9200/$i | |
printf "done! \n" | |
else | |
printf "i screwed up whilst dumping '$i', aborting..." | |
exit 1 | |
fi | |
printf "importing index '$i'..." | |
elasticdump --quiet --input=$i.json.gz --output=http://elasticsearch:9200 | |
printf "done!\n" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment