Skip to content

Instantly share code, notes, and snippets.

@karlbaillie
Created April 3, 2019 11:02
Show Gist options
  • Save karlbaillie/22c699e6e95d449807f2250d966730f9 to your computer and use it in GitHub Desktop.
Save karlbaillie/22c699e6e95d449807f2250d966730f9 to your computer and use it in GitHub Desktop.
Reindex ElasticSearch one index at a time using ElasticDump.
#!/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