Created
July 28, 2017 09:21
-
-
Save WangWenchao/0c67b12ffbdba2a4b571ad6dedf636b4 to your computer and use it in GitHub Desktop.
delete old es index
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 | |
| # example: sh delete_es_by_day.sh logstash-kettle-log logsdate 30 | |
| index_name=$1 | |
| daycolumn=$2 | |
| savedays=$3 | |
| format_day=$4 | |
| if [ ! -n "$savedays" ]; then | |
| echo "the args is not right,please input again...." | |
| exit 1 | |
| fi | |
| if [ ! -n "$format_day" ]; then | |
| format_day='%Y%m%d' | |
| fi | |
| sevendayago=`date -d "-${savedays} day " +${format_day}` | |
| curl -XDELETE "10.130.3.102:9200/${index_name}/_query?pretty" -d " | |
| { | |
| "query": { | |
| "filtered": { | |
| "filter": { | |
| "bool": { | |
| "must": { | |
| "range": { | |
| "${daycolumn}": { | |
| "from": null, | |
| "to": ${sevendayago}, | |
| "include_lower": true, | |
| "include_upper": true | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| }" | |
| echo "ok" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment