# Policy to automatically delete indexes with max days and size

**URL:** <https://discuss.elastic.co/t/policy-to-automatically-delete-indexes-with-max-days-and-size/255995>\
**Category:** Elasticsearch\
**Tags:** ilm-index-lifecycle-management\
**Created:** [November 19, 2020, 1:51pm UTC](https://discuss.elastic.co/t/policy-to-automatically-delete-indexes-with-max-days-and-size/255995 "2020-11-19T13:51:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cruizba](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cruizba/32/76115_2.png) [@cruizba](https://discuss.elastic.co/u/cruizba)\
**Post date:** [November 19, 2020, 1:51pm UTC](https://discuss.elastic.co/t/policy-to-automatically-delete-indexes-with-max-days-and-size/255995/1 "2020-11-19T13:51:23Z")

</div>

Hello to all the Elastic Stack community and developers 🙂

We have a server that use Elasticsearch to store logs, events and metrics. This server configure a policy which delete an Index if it is older that X days.

At the moment we have a situation where we define a property like that:

```auto
MAX_DAYS_DELETE=15

```

A new index is created each day, so indexes older than 15 days can be deleted.

Our server automatically set this policy to all indexes to make this work. This is an example of the policy applied:

```auto
{
  "cleanup_policy" : {
    "version" : 3,
    "modified_date" : "2020-11-13T16:47:13.011Z",
    "policy" : {
      "phases" : {
        "delete" : {
          "min_age" : "<MAX_DAYS_DELETE>d",
          "actions" : {
            "delete" : {
              "delete_searchable_snapshot" : true
            }
          }
        }
      }
    }
  }
}

```

* * *

## What is my goal

My goal is to have two parameters like this:

```auto
MAX_DAYS_DELETE=15
MAX_SIZE=100M

```

In this case, if an index is older than 15 days, it will be deleted. And if an index is exceeding such space, keep the same space (truncate old docs in this index).

## My question

Is it possible to create a policy with those requirements? I can't find a good policy setup to make something like this.

---

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [November 20, 2020, 12:03am UTC](https://discuss.elastic.co/t/policy-to-automatically-delete-indexes-with-max-days-and-size/255995/2 "2020-11-20T00:03:28Z")

</div>

AFAIK  
You can not delete documents with a policy. You will have to delete the whole index.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 20, 2020, 12:28am UTC](https://discuss.elastic.co/t/policy-to-automatically-delete-indexes-with-max-days-and-size/255995/3 "2020-11-20T00:28:14Z")

</div>

Are you creating a policy _per index_ that is created?

---

<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:** [December 18, 2020, 12:28am UTC](https://discuss.elastic.co/t/policy-to-automatically-delete-indexes-with-max-days-and-size/255995/4 "2020-12-18T00:28:16Z")

</div>

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