# Finding and deleting empty indexes

**URL:** <https://discuss.elastic.co/t/finding-and-deleting-empty-indexes/172764>\
**Category:** Elasticsearch\
**Created:** [March 18, 2019, 12:00pm UTC](https://discuss.elastic.co/t/finding-and-deleting-empty-indexes/172764 "2019-03-18T12:00:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gormanst](https://avatars.discourse-cdn.com/v4/letter/g/87869e/32.png) [@gormanst](https://discuss.elastic.co/u/gormanst)\
**Post date:** [March 18, 2019, 12:00pm UTC](https://discuss.elastic.co/t/finding-and-deleting-empty-indexes/172764/1 "2019-03-18T12:00:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Bernt\_Rostad](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@Bernt\_Rostad](https://discuss.elastic.co/u/Bernt_Rostad)\
**Post date:** [March 18, 2019, 1:00pm UTC](https://discuss.elastic.co/t/finding-and-deleting-empty-indexes/172764/2 "2019-03-18T13:00:36Z")

</div>

> [@gormanst](#):
>
> Is dealing with empty indexes a common problem

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 15, 2019, 1:00pm UTC](https://discuss.elastic.co/t/finding-and-deleting-empty-indexes/172764/3 "2019-04-15T13:00:42Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
