# Delete index automatically after particular days

**URL:** <https://discuss.elastic.co/t/delete-index-automatically-after-particular-days/251289>\
**Category:** Elasticsearch\
**Tags:** ilm-index-lifecycle-management\
**Created:** [October 7, 2020, 2:46pm UTC](https://discuss.elastic.co/t/delete-index-automatically-after-particular-days/251289 "2020-10-07T14:46:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elasticheart](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticheart/32/65189_2.png) [@elasticheart](https://discuss.elastic.co/u/elasticheart)\
**Post date:** [October 7, 2020, 2:46pm UTC](https://discuss.elastic.co/t/delete-index-automatically-after-particular-days/251289/1 "2020-10-07T14:46:13Z")

</div>

Hi,

I am using Logstash to ingest log data to elasticsearch, Indices are created daily, that every day's index has a unique name like `index_name-YYYY-MM-DD`. So, after 30 days, there will be 30 indices. On day 31st, I want the index made at day 1 to get deleted, and on 32nd day, I want 2nd day's index to get deleted.

I had a look at Index Lifecycle Policies. I will be having just `Hot` indices and no other life cycle category. I created the below CURLs.

```
curl -X PUT "localhost:9200/_ilm/policy/delete_policy?pretty" -H 'Content-Type: application/json' -d'
{
  "policy": {
    "phases": {
      "hot": {
        "actions": {
          "rollover": {
            "max_age": "30d"
          }
        }
      }
    }
  }
}
'

curl -X PUT "localhost:9200/mylogs*/_settings?pretty" -H 'Content-Type: application/json' -d'
{
  "index": {
    "lifecycle": {
      "name": "delete_policy"
    }
  }
}
'

```

Is it alright to proceed with this? Will this give me what I am looking for? Is there any change needed / suggested?

Thanks.

---

<div class="post-metadata">

**Author:** ![Wolfram\_Haussig](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfram_haussig/32/70528_2.png) [@Wolfram\_Haussig](https://discuss.elastic.co/u/Wolfram_Haussig)\
**Post date:** [October 8, 2020, 5:16am UTC](https://discuss.elastic.co/t/delete-index-automatically-after-particular-days/251289/2 "2020-10-08T05:16:59Z")

</div>

Hi,

No, this will **NOT** do what you want. This will create indizes each having the data of 30 days. You want to have a `hot phase` with a daily rollover and a [`delete phase`](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-delete.html), like(_untested_):

```auto
curl -X PUT "localhost:9200/_ilm/policy/delete_policy?pretty" -H 'Content-Type: application/json' -d'
{
  "policy": {
    "phases": {
      "hot": {
        "actions": {
          "rollover": {
            "max_age": "1d"
          }
        }
      },
        "delete" : {
          "min_age" : "30d",
          "actions" : {
            "delete" : { }
          }
        }
    }
  }
}
'

```

Best regards  
Wolfram

---

<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:** [November 5, 2020, 5:17am UTC](https://discuss.elastic.co/t/delete-index-automatically-after-particular-days/251289/3 "2020-11-05T05:17:02Z")

</div>

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