Last active
March 8, 2019 14:03
-
-
Save codeasashu/1beb230c4fe4c9f344c675f763201ef5 to your computer and use it in GitHub Desktop.
Get Elasticsearch 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
#!/bin/sh | |
##Useage: ./getes.sh | |
## To dry run query: ./getes.sh -v -x POST -d '{a:b}' http://elasticurl | |
## To actually run query: ./getes.sh -x POST -d '{a:b}' http://elasticurl | |
## Default action is search, so you can omitt -x GET switch | |
METHOD="GET" | |
DATA="{}" | |
DRYRUN=0 | |
usage() { echo "Usage: $0 [-d <json-data>] [-x <GET|POST|PUT|DELETE>] ES_URL" 1>&2; exit 1; } | |
runes() { | |
curl -s -X$METHOD -d$DATA -H'Content-type:application/json' $ES_URL | jq | less | |
} | |
dryrun() { | |
echo DEBUG:: curl -s -X$METHOD -d$DATA -H'Content-type:application/json' $ES_URL 1>&2; exit 1; | |
} | |
while getopts ":vx:d:" opt; do | |
case "$opt" in | |
d) DATA=$OPTARG | |
;; | |
x) METHOD=$OPTARG | |
;; | |
v) DRYRUN=1 | |
;; | |
*) usage | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
if [ -z $1 ]; then | |
usage | |
fi | |
ES_URL=$1 | |
if [ $DRYRUN -eq 1 ];then | |
dryrun | |
fi | |
runes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment