# How can curator delete empty indices?

**URL:** <https://discuss.elastic.co/t/how-can-curator-delete-empty-indices/145874>\
**Category:** Elasticsearch\
**Created:** [August 24, 2018, 9:02am UTC](https://discuss.elastic.co/t/how-can-curator-delete-empty-indices/145874 "2018-08-24T09:02:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohanRask](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johanrask/32/22713_2.png) [@JohanRask](https://discuss.elastic.co/u/JohanRask)\
**Post date:** [August 24, 2018, 9:02am UTC](https://discuss.elastic.co/t/how-can-curator-delete-empty-indices/145874/1 "2018-08-24T09:02:17Z")

</div>

Hi,  
We are using rollover with curator with max\_age + max\_size. In our automated index creation process we create multiple indices (think environments like like, dev, test, pre-prod etc ) BUT all of these indices are not always used so there can be 0 documents in them.

When an index is rolled over (creation\_date \> max\_age) our index is not removed since we use field\_stats filter and remove indices by timestamp.

I have not found a way to remove empty indices, can anyone help we out with this?

Regards /Johan

---

<div class="post-metadata">

**Author:** ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)\
**Post date:** [August 24, 2018, 3:06pm UTC](https://discuss.elastic.co/t/how-can-curator-delete-empty-indices/145874/2 "2018-08-24T15:06:41Z")

</div>

Field stats can’t do a document count on an empty index. You’ll have to figure out a different attribute to identity your indices. `creation_date` is still available, and index name.

You may also have to use your own scripting with the `_cat` API to identify empty indices and delete them with curl, or a similar tool.

---

<div class="post-metadata">

**Author:** ![JohanRask](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johanrask/32/22713_2.png) [@JohanRask](https://discuss.elastic.co/u/JohanRask)\
**Post date:** [August 26, 2018, 8:27pm UTC](https://discuss.elastic.co/t/how-can-curator-delete-empty-indices/145874/3 "2018-08-26T20:27:19Z")

</div>

Thanks @theuntergeek,

I only want to check if doc\_count is 0, nothing else. I already exclude all indices with a write alias. Is it still not possible?

I could easily fix this with ansible and the http api but it would be nice if curator could fix it for me.

Regards /Johan

---

<div class="post-metadata">

**Author:** ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)\
**Post date:** [August 27, 2018, 1:59am UTC](https://discuss.elastic.co/t/how-can-curator-delete-empty-indices/145874/4 "2018-08-27T01:59:06Z")

</div>

There is no doc count filter, so you'd have to do some other clever work with filters to use other metrics if you wanted to use Curator. Either that, or script up some python using the Curator API.

---

<div class="post-metadata">

**Author:** ![JohanRask](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johanrask/32/22713_2.png) [@JohanRask](https://discuss.elastic.co/u/JohanRask)\
**Post date:** [August 27, 2018, 1:56pm UTC](https://discuss.elastic.co/t/how-can-curator-delete-empty-indices/145874/5 "2018-08-27T13:56:12Z")

</div>

Hi,

Ok, I understand. Is a doc count filter something that would be of interest for curator if I try to add this feature?  
Regards /Johan

---

<div class="post-metadata">

**Author:** ![JohanRask](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johanrask/32/22713_2.png) [@JohanRask](https://discuss.elastic.co/u/JohanRask)\
**Post date:** [August 27, 2018, 8:39pm UTC](https://discuss.elastic.co/t/how-can-curator-delete-empty-indices/145874/6 "2018-08-27T20:39:59Z")

</div>

@theuntergeek,

I can see from the code that there already is a filter\_empty function but it is not exposed as a filter ([https://github.com/elastic/curator/blob/5fdcc337625c6a7e9aeeb90de625b54b92cbbcb7/curator/indexlist.py#L722](https://github.com/elastic/curator/blob/5fdcc337625c6a7e9aeeb90de625b54b92cbbcb7/curator/indexlist.py#L722)).  
A simple (not sure if it is the best though) would be to expose this as a new filter

```
- filtertype: empty
exclude: False

```

Or is there any reason why this would not fit in curator?

Regards /Johan

---

<div class="post-metadata">

**Author:** ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)\
**Post date:** [August 27, 2018, 10:12pm UTC](https://discuss.elastic.co/t/how-can-curator-delete-empty-indices/145874/7 "2018-08-27T22:12:24Z")

</div>

Oh, yeah. I did make that. It's used on [line 301](https://github.com/elastic/curator/blob/5fdcc337625c6a7e9aeeb90de625b54b92cbbcb7/curator/indexlist.py#L301). I haven't exposed it for general use, but I suppose since it's there, it could be.

It would need to be added to:

- Documentation
- The filter schema(s)
- ???

There are already tests for it, so I think that might be all that's required to add it.

---

<div class="post-metadata">

**Author:** ![JohanRask](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johanrask/32/22713_2.png) [@JohanRask](https://discuss.elastic.co/u/JohanRask)\
**Post date:** [August 28, 2018, 6:17am UTC](https://discuss.elastic.co/t/how-can-curator-delete-empty-indices/145874/8 "2018-08-28T06:17:52Z")

</div>

Great! I am on it, I will send and PR.

/Johan

---

<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:** [September 25, 2018, 6:17am UTC](https://discuss.elastic.co/t/how-can-curator-delete-empty-indices/145874/9 "2018-09-25T06:17:56Z")

</div>

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