Skip to content

Instantly share code, notes, and snippets.

@josue
Created August 26, 2015 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josue/1ac01cf8b3d69cdab28a to your computer and use it in GitHub Desktop.
Save josue/1ac01cf8b3d69cdab28a to your computer and use it in GitHub Desktop.
ElasticSearch - Displays quick indices info (name / size / count / alias)
#!/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]'
@josue
Copy link
Author

josue commented Aug 26, 2015

Requires: jq - https://stedolan.github.io/jq/

jq is a lightweight and flexible command-line JSON processor.

Usage:

./es_quick_info.sh "my_host_name:9200"

Example output:

{
  "sample_index_production": {
    "size": "5.3gb",
    "count": 2734052,
    "alias": [
      "production"
    ]
  },
  "sample_index_staging": {
    "size": "1.1gb",
    "count": 34142,
    "alias": [
      "staging",
      "dev"
    ]
  }
}

@wricardo
Copy link

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment