This script I've used to help me work out how many shards an index on my cluster has and the average shard size for that index.
curl -XGET 'localhost:9200/_cat/segments?v&h=index,shard,segment,size,docCount,deleted&pretty' -o index-shards.txtawk '
NR>1 {
idx=$1
size=$4
if (size ~ /gb$/) {
sub(/gb/, "", size)
size_gb=size
} else if (size ~ /mb$/) {
sub(/mb/, "", size)
size_gb=size/1024
} else if (size ~ /kb$/) {
sub(/kb$/, "", size)
size_gb = size / (1024 * 1024)
} else {
next
}
cnt[idx]++
sum_gb[idx]+=size_gb
}
END {
for (i in cnt)
printf "%s\t%d\t%.2fGB\n", i, cnt[i], sum_gb[i]/cnt[i]
}' index-shards.txt