Created
June 4, 2019 16:23
-
-
Save ilyaevseev/76d37e8cd5584976424c650e34d4cc76 to your computer and use it in GitHub Desktop.
Delete old time-based indexes from ElasticSearch
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/sh | |
MAX_DAYS="30" | |
ES_ADDR="127.0.0.1" | |
D0="$(date -d "$MAX_DAYS days ago" +%s)" | |
curl -sS "http://$ES_ADDR:9200/_cat/indices" | | |
awk 'match($3, /-([0-9][0-9][0-9][0-9])[\.\-]([0-9][0-9])[\.\-]([0-9][0-9])$/, m) { printf "%s-%s-%s %s\n", m[1],m[2],m[3],$3 }' | | |
while read D1 idx; do | |
D2="$(date -d "$D1" +%s 2>/dev/null || :)" | |
test "$D2" = "" && continue | |
test "$D2" -ge "$D0" && continue | |
result="$(curl -sS -X DELETE "http://$ES_ADDR:9200/$idx")" | |
test "$result" = '{"acknowledged":true}' && continue | |
echo "FAILED: $idx: $result" | |
exit 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment