Created
August 26, 2015 16:08
-
-
Save josue/1ac01cf8b3d69cdab28a to your computer and use it in GitHub Desktop.
ElasticSearch - Displays quick indices info (name / size / count / alias)
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 | |
# Ensure file is executable: chmod +x es_quick_info.sh | |
# Use given host or default to localhost | |
[ "$1" != "" ] && HOST=$1 || HOST="localhost:9200" | |
ES_EXIST=`curl -s "$HOST" | grep 'ok'` | |
if [ "$ES_EXIST" = "" ]; then | |
echo "Error: ElasticSearch host ($HOST) does not exist." | |
exit 1 | |
fi | |
# Get indices name/size/count | |
ES_1=`curl -s "$HOST/_stats" | jq '.indices | [(keys - ["data"])[] as $key | { ($key): .[$key] | .total | { size:.store.size, count:.docs.count } }] | add'` | |
# Get indices aliases | |
ES_2=`curl -s "$HOST/_aliases" | jq '[(keys - ["data"])[] as $key | { ($key): { alias: .[$key] | .aliases | keys } }] | add'` | |
# Merge both results into one | |
echo $ES_1 $ES_2 | jq -s '.[0] * .[1]' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires: jq - https://stedolan.github.io/jq/
Usage:
./es_quick_info.sh "my_host_name:9200"
Example output: