# Delete Index after x amount of days

**URL:** https://discuss.elastic.co/t/delete-index-after-x-amount-of-days/246492
**Category:** Elasticsearch
**Created:** [August 26, 2020, 5:15pm UTC](https://discuss.elastic.co/t/delete-index-after-x-amount-of-days/246492 "2020-08-26T17:15:16Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![userR](https://avatars.discourse-cdn.com/v4/letter/u/22d042/32.png) [@userR](https://discuss.elastic.co/u/userR)
#### Post date: [August 26, 2020, 5:15pm UTC](https://discuss.elastic.co/t/delete-index-after-x-amount-of-days/246492/1 "2020-08-26T17:15:16Z")

</div>

Currently reading logs from Logstash to Elasticsearch and creating daily indexes. Is there a way to delete each of these indexes after an X amount of days?  
Also, is there an auto delete feature when my elasticsearch cluster runs out of storage?

---

<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: [August 26, 2020, 9:48pm UTC](https://discuss.elastic.co/t/delete-index-after-x-amount-of-days/246492/2 "2020-08-26T21:48:43Z")

</div>

[ILM](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-start.html) is the best thing for what you want.

---

<div class="post-metadata">

### Author: ![userR](https://avatars.discourse-cdn.com/v4/letter/u/22d042/32.png) [@userR](https://discuss.elastic.co/u/userR)
#### Post date: [August 27, 2020, 12:12am UTC](https://discuss.elastic.co/t/delete-index-after-x-amount-of-days/246492/3 "2020-08-27T00:12:48Z")

</div>

I've created an Index Lifecycle Policy but my daily log indexes don't show up when I try to apply the policy to an index template. Is there an extra step I'm missing?

---

<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: [August 27, 2020, 12:18am UTC](https://discuss.elastic.co/t/delete-index-after-x-amount-of-days/246492/4 "2020-08-27T00:18:07Z")

</div>

Can you share your policy and index template where that's been applied?

---

<div class="post-metadata">

### Author: ![userR](https://avatars.discourse-cdn.com/v4/letter/u/22d042/32.png) [@userR](https://discuss.elastic.co/u/userR)
#### Post date: [August 27, 2020, 12:32am UTC](https://discuss.elastic.co/t/delete-index-after-x-amount-of-days/246492/5 "2020-08-27T00:32:02Z")

</div>

![Screen Shot 2020-08-26 at 5.29.26 PM](https://us1.discourse-cdn.com/elastic/original/3X/f/1/f1b22efd32bbf664fc84b737c1d3c1b1d55c9176.png) ![Screen Shot 2020-08-26 at 5.30.06 PM](https://us1.discourse-cdn.com/elastic/original/3X/8/a/8a59ca6b442940a2c457bdb1d747a384d05d2f4f.png)

Here are my settings for the Policy and template. What I want the policy to do is to delete the daily indexes after two weeks. My current set up, I believe, will delete all the indexes after two weeks and then start repopulating.

My indexes are set up like this: "jira-year.month.day"

---

<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: [August 27, 2020, 12:45am UTC](https://discuss.elastic.co/t/delete-index-after-x-amount-of-days/246492/6 "2020-08-27T00:45:16Z")

</div>

You might need to check with the [explain API](https://www.elastic.co/guide/en/elasticsearch/reference/7.9/ilm-explain-lifecycle.html) to see what's happening.

---

<div class="post-metadata">

### Author: ![userR](https://avatars.discourse-cdn.com/v4/letter/u/22d042/32.png) [@userR](https://discuss.elastic.co/u/userR)
#### Post date: [August 27, 2020, 12:57am UTC](https://discuss.elastic.co/t/delete-index-after-x-amount-of-days/246492/7 "2020-08-27T00:57:54Z")

</div>

{  
"indices" : {  
"jiralogdata-2020.08.21" : {  
"index" : "jiralogdata-2020.08.21",  
"managed" : false  
}  
}  
}  
Looks like the policy isn't being applied, not sure why

---

<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: [August 27, 2020, 1:03am UTC](https://discuss.elastic.co/t/delete-index-after-x-amount-of-days/246492/8 "2020-08-27T01:03:29Z")

</div>

Thanks! Can you try [https://www.elastic.co/guide/en/elasticsearch/reference/7.9/set-up-lifecycle-policy.html#apply-policy-multiple](https://www.elastic.co/guide/en/elasticsearch/reference/7.9/set-up-lifecycle-policy.html#apply-policy-multiple)

---

<div class="post-metadata">

### Author: ![userR](https://avatars.discourse-cdn.com/v4/letter/u/22d042/32.png) [@userR](https://discuss.elastic.co/u/userR)
#### Post date: [August 27, 2020, 1:24am UTC](https://discuss.elastic.co/t/delete-index-after-x-amount-of-days/246492/9 "2020-08-27T01:24:03Z")

</div>

Great! That seemed to add the policy. Is there a way get when the log will be deleted? I'm only getting the information below:

```
"indices" : {
    "jiralogdata-2020.08.22" : {
      "index" : "jiralogdata-2020.08.22",
      "managed" : true,
      "policy" : "Delete_Index_After_2_weeks",
      "lifecycle_date_millis" : 1598054395357,
      "age" : "5.05d",
      "phase" : "hot",
      "phase_time_millis" : 1598491271739,
      "action" : "complete",
      "action_time_millis" : 1598491272042,
      "step" : "complete",
      "step_time_millis" : 1598491272042,
      "phase_execution" : {
        "policy" : "Delete_Index_After_2_weeks",
        "phase_definition" : {
          "min_age" : "0ms",
          "actions" : {
            "set_priority" : {
              "priority" : 100
            }
          }
        },
```

---

<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: [August 27, 2020, 1:32am UTC](https://discuss.elastic.co/t/delete-index-after-x-amount-of-days/246492/10 "2020-08-27T01:32:25Z")

</div>

By [default](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-settings.html), the cluster will check if there are ILM policies it needs to execute.

So you should see something happening after 20 min at the most.

---

<div class="post-metadata">

### Author: ![userR](https://avatars.discourse-cdn.com/v4/letter/u/22d042/32.png) [@userR](https://discuss.elastic.co/u/userR)
#### Post date: [August 27, 2020, 1:49am UTC](https://discuss.elastic.co/t/delete-index-after-x-amount-of-days/246492/11 "2020-08-27T01:49:48Z")

</div>

Great thanks for your help!

---

<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 24, 2020, 1:49am UTC](https://discuss.elastic.co/t/delete-index-after-x-amount-of-days/246492/12 "2020-09-24T01:49:52Z")

</div>

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