Last active
December 26, 2018 06:29
-
-
Save wudi/3f7c6b7cd93e9f235c04d7c0e23175b9 to your computer and use it in GitHub Desktop.
clean elasticsearch expired data
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
#!/usr/bin/env bash | |
#Copyright (C) 2018 Eagle <[email protected]> | |
ES_HOST="http://127.0.0.1:9200" | |
SEVEN_DAYS_AGO=$(date -d "-7 day" +%Y.%m.%d) | |
THREE_DAYS_AGO=$(date -d "-3 day" +%Y.%m.%d) | |
declare -a INDEX_FOR_SEVEN=( | |
"filebeat-xxx-" | |
"filebeat-yyy-" | |
) | |
declare -a INDEX_FOR_THREE=( | |
"filebeat-xxx-" | |
"filebeat-yyy-" | |
".monitoring-es-6-" | |
) | |
function cleanIndex { | |
index=$1 | |
echo "Clean index $index" | |
curl -XDELETE "${ES_HOST}/$index" | |
echo "" | |
} | |
for i in "${INDEX_FOR_SEVEN[@]}" | |
do | |
cleanIndex "${i}${SEVEN_DAYS_AGO}" | |
done | |
for i in "${INDEX_FOR_THREE[@]}" | |
do | |
cleanIndex "${i}${THREE_DAYS_AGO}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run at 1 a.m every day.