Skip to content

Instantly share code, notes, and snippets.

@lotherk
Last active February 21, 2018 09:28
Show Gist options
  • Save lotherk/5da4d49a2f20a7b15d0ef589f0a04ba7 to your computer and use it in GitHub Desktop.
Save lotherk/5da4d49a2f20a7b15d0ef589f0a04ba7 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# reindex elastic search indizies
#
# might destroy everything, don't use.
RES=$(curl -s 'localhost:9200/_cat/indices' |awk -F ' ' '{print $3}')
echo $RES
for r in $RES; do
reindex_data="'{
\"source\": {
\"index\": \"${r}\"
},
\"dest\": {
\"index\": \"${r}-reindex\"
}
}'"
alias_data="'{
\"actions\": [
{ \"add\": {
\"index\": \"${r}-reindex\",
\"alias\": \"${r}\"
}
},
{ \"remove_index\": {
\"index\": \"${r}\"
}
}
]
}'"
reindex_curl="curl -XPOST 'http://localhost:9200/_reindex?wait_for_completion' -H 'Content-Type: application/json' -d${reindex_data}"
alias_curl="curl -XPOST 'http://localhost:9200/_aliases' -H 'Content-Type: application/json' -d${alias_data}"
echo "\nreindex ${r}..."
eval $reindex_curl || exit $?
echo "\nalias ${r} <- ${r}-reindex..."
eval $alias_curl || exit $?
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment