Created
June 12, 2017 09:14
-
-
Save julcap/7e0529ceeed4a8b76d01c293fedfaecf to your computer and use it in GitHub Desktop.
Manage Logstash indices, remove data of specific type
This file contains 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 | |
indices="$(curator show indices --all-indices)" | |
_type="activitylog-syslog" | |
opt=$1 | |
if [ ! "$1" ];then opt='False';fi | |
case $opt in | |
'-d') | |
# Delete all data in all indices of the given type | |
for index in $indices; do | |
echo -n "> Deleting data -> " | |
curl -XDELETE 'http://localhost:9200/'$index'/_query?q=_type:'$_type | |
echo | |
done | |
;; | |
'-q') | |
# Query all data for a given type in all indices | |
for index in $indices; do | |
echo -n "> Querying data -> " | |
curl -XGET 'http://localhost:9200/'$index'/_query?q=_type:'$_type | |
echo | |
done | |
;; | |
'-D') | |
# Completely remove all data and type from indices | |
for index in $indices; do | |
echo -n "> Deleting type: $_type -> " | |
curl -XGET 'http://localhost:9200/'$index'/'$_type | |
echo | |
done | |
;; | |
*) | |
echo | |
echo "Tool for logstash indices management" | |
echo | |
echo "Usage:" | |
echo "$(basename $0) indice_name" | |
echo | |
echo "Options:" | |
echo | |
echo "-d\tDelete all data in all indices of the given type" | |
echo "-D\tCompletely remove all data and type from indices" | |
echo "-q\tQuery all data for a given type in all indices" | |
echo | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment