# Delete index older than a week

**URL:** https://discuss.elastic.co/t/delete-index-older-than-a-week/320737
**Category:** Elasticsearch
**Created:** [December 8, 2022, 5:33am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737 "2022-12-08T05:33:58Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Neelam\_Zanvar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/neelam_zanvar/32/103116_2.png) [@Neelam\_Zanvar](https://discuss.elastic.co/u/Neelam_Zanvar)
#### Post date: [December 8, 2022, 5:33am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/1 "2022-12-08T05:33:58Z")

</div>

Currently i have logs from 5 to 6 servers coming to elk. I want to delete all indices older than a week. what is the best way to achieve this? i went through ILM but didn't get the exact way to do this

---

<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: [December 8, 2022, 5:36am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/2 "2022-12-08T05:36:48Z")

</div>

[ILM](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-lifecycle-management.html) can definitely do that - [Delete | Elasticsearch Guide [8.5] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-delete.html)

---

<div class="post-metadata">

### Author: ![Venkata\_Raja](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/venkata_raja/32/114264_2.png) [@Venkata\_Raja](https://discuss.elastic.co/u/Venkata_Raja)
#### Post date: [December 8, 2022, 5:38am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/3 "2022-12-08T05:38:14Z")

</div>

Are you generating daily indices or one index , If daily indices disable rollover in hot phase and put 7 days at delete phase. if one index , try using rollover after 7 days in hot and put 0 days at delete phase.  
For more info:

> **[Tutorial: Automate rollover with ILM | Elasticsearch Guide \[8.5\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/8.5/getting-started-index-lifecycle-management.html#ilm-gs-create-policy)**

---

<div class="post-metadata">

### Author: ![dadiasish](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadiasish/32/114221_2.png) [@dadiasish](https://discuss.elastic.co/u/dadiasish)
#### Post date: [December 8, 2022, 5:40am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/4 "2022-12-08T05:40:49Z")

</div>

The best way and easy way to do it via the Kibana UI.

You can go to Stack Management --\> Index Lifecycle Management --\> Create Policy and here in the Hot phase, set the number of days you want a particular index to be in Elasticsearch and then remove the Cold phase.

Automatically after 7 days the data will be deleted.

---

<div class="post-metadata">

### Author: ![Neelam\_Zanvar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/neelam_zanvar/32/103116_2.png) [@Neelam\_Zanvar](https://discuss.elastic.co/u/Neelam_Zanvar)
#### Post date: [December 8, 2022, 5:41am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/5 "2022-12-08T05:41:31Z")

</div>

When i select ILm and create a new policy i am only getting hot, warm and cold phase. no delete phase. Indices are created on a daily basis index\_name-@timestamp i want to delete all indices after 7 days

---

<div class="post-metadata">

### Author: ![dadiasish](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadiasish/32/114221_2.png) [@dadiasish](https://discuss.elastic.co/u/dadiasish)
#### Post date: [December 8, 2022, 5:43am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/6 "2022-12-08T05:43:13Z")

</div>

In hot phase, you'll expand in advance settings, you'll find infinite and delete symbol on your right.

Change from infinite to delete.

The delete phase will appear.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/5/95f2dbff8c9dea04409c62ee30ebd7dbba9fdaa6.png)

---

<div class="post-metadata">

### Author: ![Neelam\_Zanvar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/neelam_zanvar/32/103116_2.png) [@Neelam\_Zanvar](https://discuss.elastic.co/u/Neelam_Zanvar)
#### Post date: [December 8, 2022, 5:45am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/7 "2022-12-08T05:45:43Z")

</div>

![image](https://us1.discourse-cdn.com/elastic/original/3X/0/9/09525c727d2099fd6a49d35fe7e9dc996f8f864b.png)  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/1/f1e24e832cea6dc3f5c9399a7356c9e57e0e18eb.png)  
Is this configuration going to delete indices older than 2 days?

---

<div class="post-metadata">

### Author: ![dadiasish](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadiasish/32/114221_2.png) [@dadiasish](https://discuss.elastic.co/u/dadiasish)
#### Post date: [December 8, 2022, 5:47am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/8 "2022-12-08T05:47:14Z")

</div>

Yes, it'll.

---

<div class="post-metadata">

### Author: ![Venkata\_Raja](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/venkata_raja/32/114264_2.png) [@Venkata\_Raja](https://discuss.elastic.co/u/Venkata_Raja)
#### Post date: [December 8, 2022, 5:47am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/9 "2022-12-08T05:47:50Z")

</div>

Click on Advanced settings in hot phase , turn off enable rollover then data will be deleted after 2 days if you put 2 days in delete phase

---

<div class="post-metadata">

### Author: ![Neelam\_Zanvar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/neelam_zanvar/32/103116_2.png) [@Neelam\_Zanvar](https://discuss.elastic.co/u/Neelam_Zanvar)
#### Post date: [December 8, 2022, 5:48am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/10 "2022-12-08T05:48:07Z")

</div>

ok. so i saved it. and now on the index when i try to add policy to it i am getting this

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/9/69c19aaf33fe7f33457b19e5b2e237c49f8e0789.png)

---

<div class="post-metadata">

### Author: ![Neelam\_Zanvar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/neelam_zanvar/32/103116_2.png) [@Neelam\_Zanvar](https://discuss.elastic.co/u/Neelam_Zanvar)
#### Post date: [December 8, 2022, 5:55am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/11 "2022-12-08T05:55:48Z")

</div>

Ok. So currently in the policy ive selected delete this index after this phase and disabled the enable rollover. and in delete phase i've set it to two days. So i have a index say index\_name-@timestamp with timestamp of 5 days old. will it delete all indices older than 2 days?

---

<div class="post-metadata">

### Author: ![Neelam\_Zanvar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/neelam_zanvar/32/103116_2.png) [@Neelam\_Zanvar](https://discuss.elastic.co/u/Neelam_Zanvar)
#### Post date: [December 8, 2022, 5:57am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/12 "2022-12-08T05:57:14Z")

</div>

But daily a new index is getting created with the date. How can i attach a policy to this index? i mean which index should i apply this policy on

---

<div class="post-metadata">

### Author: ![dadiasish](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadiasish/32/114221_2.png) [@dadiasish](https://discuss.elastic.co/u/dadiasish)
#### Post date: [December 8, 2022, 5:58am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/13 "2022-12-08T05:58:51Z")

</div>

All these indexes will have an alias name, and using that it identifies the indices.

---

<div class="post-metadata">

### Author: ![Neelam\_Zanvar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/neelam_zanvar/32/103116_2.png) [@Neelam\_Zanvar](https://discuss.elastic.co/u/Neelam_Zanvar)
#### Post date: [December 8, 2022, 5:59am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/14 "2022-12-08T05:59:43Z")

</div>

how can i give the alias name?

---

<div class="post-metadata">

### Author: ![dadiasish](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadiasish/32/114221_2.png) [@dadiasish](https://discuss.elastic.co/u/dadiasish)
#### Post date: [December 8, 2022, 6:01am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/15 "2022-12-08T06:01:57Z")

</div>

please go through the URL which @Venkata_Raja has given.

It tells you everything which is required.

Thanks.

---

<div class="post-metadata">

### Author: ![Neelam\_Zanvar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/neelam_zanvar/32/103116_2.png) [@Neelam\_Zanvar](https://discuss.elastic.co/u/Neelam_Zanvar)
#### Post date: [December 8, 2022, 7:25am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/16 "2022-12-08T07:25:48Z")

</div>

I went through the doc u shared. but i am not getting anything. I've created a policy as u said. But i am confused as to how to create a template, alias and al.

---

<div class="post-metadata">

### Author: ![Venkata\_Raja](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/venkata_raja/32/114264_2.png) [@Venkata\_Raja](https://discuss.elastic.co/u/Venkata_Raja)
#### Post date: [December 8, 2022, 7:28am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/17 "2022-12-08T07:28:51Z")

</div>

Alias was not needed in your case i guess as you are disabling rollover. Just create an Index template with the exact pattern that will match all your indices and attach ILM policy to that index as shown in that link.

---

<div class="post-metadata">

### Author: ![Neelam\_Zanvar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/neelam_zanvar/32/103116_2.png) [@Neelam\_Zanvar](https://discuss.elastic.co/u/Neelam_Zanvar)
#### Post date: [December 8, 2022, 7:39am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/18 "2022-12-08T07:39:09Z")

</div>

ok. I'm stuck in creating index template only. i selected create new template. as there was no existing template for all my indices

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/d/4/d4390da56be329baec273dd2c1461f4ab9983b70.png)  
skipped all the other steps after entering the index pattern.

---

<div class="post-metadata">

### Author: ![Neelam\_Zanvar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/neelam_zanvar/32/103116_2.png) [@Neelam\_Zanvar](https://discuss.elastic.co/u/Neelam_Zanvar)
#### Post date: [December 8, 2022, 7:44am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/19 "2022-12-08T07:44:42Z")

</div>

created policy. created template that matches all the indices, with no other settings. mapped the policy to the index which has timestamp attached to it? how to attach it to the template?

---

<div class="post-metadata">

### Author: ![Neelam\_Zanvar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/neelam_zanvar/32/103116_2.png) [@Neelam\_Zanvar](https://discuss.elastic.co/u/Neelam_Zanvar)
#### Post date: [December 8, 2022, 9:34am UTC](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737/20 "2022-12-08T09:34:23Z")

</div>

I created the index template with these settings

```auto
{
  "index": {
    "lifecycle": {
      "name": "indices-10"
    },
    "number_of_shards": "1",
    "number_of_replicas": "1"
  }
}

```

indices-10 policy is

```auto
PUT _ilm/policy/indices-10
{
  "policy": {
    "phases": {
      "hot": {
        "min_age": "0ms",
        "actions": {
          "set_priority": {
            "priority": 100
          }
        }
      },
      "delete": {
        "min_age": "2d",
        "actions": {
          "delete": {
            "delete_searchable_snapshot": true
          }
        }
      }
    }
  }
}

```

Do i need to make any changes to logstash config? how will this start working? how can i test it or apply it?

logstash config

```auto
input {
  beats {
    port => 5044
  }
}

output {
  elasticsearch {
    hosts => "http://*.*.*.*:9200"
    index => "%{type}%{+YYYY.MM.dd}"
    user => "e***"
    password => " *****"
  }
}

```

[Next page](https://discuss.elastic.co/t/delete-index-older-than-a-week/320737.md?page=2)
