I am using the RestHighLevelClient to try and find then delete empty indexes. I can't find anything in the API that makes getting empty indexes simple. Is this something that is usually handled by Curator? Is dealing with empty indexes a common problem and if so I would be so grateful for a push in the right direction?
Not in my business, so I usually delete unwanted indices, whether empty or not, manually.
I did write a script a while back that lists all indices in a cluster with a doc count. To identify empty indices you can do something like this:
#!/bin/bash
srv="localhost:9200"
for idx in $(curl -XGET "http://$srv/_all/_settings?pretty" -s | jq 'keys' | sed 's/["|,]//g' | grep -E '[[:alpha:]]+'); do
count=$(curl -X GET "http://$srv/$idx/_count" -s | jq '.count')
if (( $count == 0 )); then
echo "** Index $idx is empty ... delete it"
curl -XDELETE "http://$srv/$idx"
else·
echo "Count $idx -> $count"
fi
done
I've just extracted the host as a variable ($srv) in case running from a different server.
4 Likes
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.