Skip to content

Instantly share code, notes, and snippets.

@wudi
Last active December 26, 2018 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wudi/3f7c6b7cd93e9f235c04d7c0e23175b9 to your computer and use it in GitHub Desktop.
Save wudi/3f7c6b7cd93e9f235c04d7c0e23175b9 to your computer and use it in GitHub Desktop.
clean elasticsearch expired data
#!/usr/bin/env bash
#Copyright (C) 2018 Eagle <eaglewudi@gmail.com>
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
@wudi
Copy link
Author

wudi commented Dec 26, 2018

0 0 1 * * /data/app/shell/es_expired_clean.sh > /dev/null 2>&1

Run at 1 a.m every day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment