Skip to content

Instantly share code, notes, and snippets.

@jclosure
Created June 4, 2015 20:50
Show Gist options
  • Save jclosure/80a138d717a31071af18 to your computer and use it in GitHub Desktop.
Save jclosure/80a138d717a31071af18 to your computer and use it in GitHub Desktop.
Bash Script to Trim Elasticsearch By Date Indexes
#!/bin/bash
DAYS_AGO=$1
TARGET_INDEX=logstash-`date --date="$DAYS_AGO days ago" +%Y.%m.%d`;
if [[ "$DAYS_AGO" ]]; then
# echo "computed target index: $TARGET_INDEX"
curl -XDELETE "http://localhost:9200/$TARGET_INDEX"
else
echo "you need to pass in a parameter for DAYS_AGO" | mail -s "no days passed to script. cannot delete ES index: $TARGET_INDEX" [email protected]
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment