# \[ElasticSearch v.7.5\] How to delete all indexes older than 6 month automatically?

**URL:** https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036
**Category:** Elasticsearch
**Created:** [January 14, 2024, 7:06pm UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036 "2024-01-14T19:06:31Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![mpniel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mpniel/32/113170_2.png) [@mpniel](https://discuss.elastic.co/u/mpniel)
#### Post date: [January 14, 2024, 7:06pm UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/1 "2024-01-14T19:06:31Z")

</div>

How to delete all indexes older than 6 month automatically?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 15, 2024, 3:21am UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/2 "2024-01-15T03:21:54Z")

</div>

I would:

- Upgrade to at least 7.17 as a matter of urgency
- Ideally upgrade to 8.11
- Use ILM. See [ILM: Manage the index lifecycle | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-lifecycle-management.html) or [ILM: Manage the index lifecycle | Elasticsearch Guide [7.17] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/index-lifecycle-management.html) for 7.17

---

<div class="post-metadata">

### Author: ![mpniel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mpniel/32/113170_2.png) [@mpniel](https://discuss.elastic.co/u/mpniel)
#### Post date: [January 16, 2024, 5:05pm UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/3 "2024-01-16T17:05:22Z")

</div>

Take into account that it is currently not possible to perform the upgrade, what are the steps for deleting all indexes older than six months automatically?

---

<div class="post-metadata">

### Author: ![mpniel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mpniel/32/113170_2.png) [@mpniel](https://discuss.elastic.co/u/mpniel)
#### Post date: [January 16, 2024, 5:08pm UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/4 "2024-01-16T17:08:26Z")

</div>

In addition , the provided link is very large and have many chapters that I don't know where to find what I need and what action plan should I do in order to achieve my simple request of delete all indexes older than 6 month.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 16, 2024, 8:38pm UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/5 "2024-01-16T20:38:27Z")

</div>

What are your index names?

---

<div class="post-metadata">

### Author: ![mpniel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mpniel/32/113170_2.png) [@mpniel](https://discuss.elastic.co/u/mpniel)
#### Post date: [January 16, 2024, 9:17pm UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/6 "2024-01-16T21:17:10Z")

</div>

myindex\_2023\_04  
myindex1\_2023\_05\_14  
myindex3-2023-06

sample

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 16, 2024, 9:37pm UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/7 "2024-01-16T21:37:32Z")

</div>

Once you have identified the list of indices, you can run:

```
DELETE index1,index2,index3

```

Or you can try to generate the index name using date maths. See [Date math support in index and index alias names | Elasticsearch Guide [7.17] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/date-math-index-names.html)

---

<div class="post-metadata">

### Author: ![mpniel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mpniel/32/113170_2.png) [@mpniel](https://discuss.elastic.co/u/mpniel)
#### Post date: [January 16, 2024, 9:54pm UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/8 "2024-01-16T21:54:25Z")

</div>

‏the question was how to delete indexes older than 6 months.  
‏we have a large amount of indexes with different names and each index have monthly or daily fashion

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 16, 2024, 10:14pm UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/9 "2024-01-16T22:14:35Z")

</div>

That's what I wrote with date math. You can use that with some wildcards I guess.

But ideally use ILM. That will make your life easier.

Otherwise a shell script and iterate over the list of indices. You might have the creation date as a metadata.

---

<div class="post-metadata">

### Author: ![mpniel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mpniel/32/113170_2.png) [@mpniel](https://discuss.elastic.co/u/mpniel)
#### Post date: [January 17, 2024, 9:40am UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/10 "2024-01-17T09:40:17Z")

</div>

‏What is the detailed action plant to configure ILM to do the that?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 17, 2024, 10:10am UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/11 "2024-01-17T10:10:32Z")

</div>

You should read [the documentation](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/index-lifecycle-management.html).

With recent versions of Kibana, you would be most likely guided to configure all that from the Kibana admin interface. Not sure about your old version though. Give it a look.

But basically, you'd need to define a [Delete Policy](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/ilm-delete.html).

Probably as well, apply manually the policy to your index: [Manage existing indices | Elasticsearch Guide [7.17] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/ilm-with-existing-indices.html)

You have an API example in that page: [Configure a lifecycle policy | Elasticsearch Guide [7.17] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/set-up-lifecycle-policy.html#ilm-create-policy)

Basically something like:

```auto
PUT _ilm/policy/my_policy
{
  "policy": {
    "phases": {
      "delete": {
        "min_age": "180d",
        "actions": {
          "delete": {} 
        }
      }
    }
  }
}

```

```auto
PUT index-names*/_settings 
{
  "index": {
    "lifecycle": {
      "name": "my_policy"
    }
  }
}

```

And if ILM is not started yet:

```auto
POST _ilm/start

```

Alternatively, you could have a look at [Curator Reference [8.0] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/curator/current/index.html)

---

<div class="post-metadata">

### Author: ![mpniel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mpniel/32/113170_2.png) [@mpniel](https://discuss.elastic.co/u/mpniel)
#### Post date: [January 17, 2024, 11:17am UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/12 "2024-01-17T11:17:06Z")

</div>

Thank you very much.  
‏Is it possible to use the last version of kibana with Elasticsearch 7.5?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 17, 2024, 12:42pm UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/13 "2024-01-17T12:42:54Z")

</div>

> [@mpniel](#):
>
> Is it possible to use the last version of kibana with Elasticsearch 7.5?

No it's not.

---

<div class="post-metadata">

### Author: ![mpniel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mpniel/32/113170_2.png) [@mpniel](https://discuss.elastic.co/u/mpniel)
#### Post date: [January 28, 2024, 10:09pm UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/14 "2024-01-28T22:09:38Z")

</div>

1. ‏How to set a delete policy as a default for any index that will be created in the future?

2. How set a delete policy for all existing indices?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 29, 2024, 1:42am UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/15 "2024-01-29T01:42:48Z")

</div>

What did you try so far? What can you see on Kibana? What is unclear?

---

<div class="post-metadata">

### Author: ![mpniel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mpniel/32/113170_2.png) [@mpniel](https://discuss.elastic.co/u/mpniel)
#### Post date: [January 29, 2024, 7:53pm UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/16 "2024-01-29T19:53:37Z")

</div>

I will rewrite better my previous questions

1. ‏Is it posible to set a delete policy as a default for any index that will be created in the future?
2. Is it possible to set a delete policy for all existing indices?

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [January 29, 2024, 7:59pm UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/17 "2024-01-29T19:59:36Z")

</div>

> [@mpniel](#):
>
> ‏Is it posible to set a delete policy as a default for any index that will be created in the future?

Yes, you can do this through an index template. Look at the links David provided above for details.

> [@mpniel](#):
>
> Is it possible to set a delete policy for all existing indices?

Yes can do this by updating the settings of all or a selection of indices. Look at the example David provided.

---

<div class="post-metadata">

### Author: ![mpniel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mpniel/32/113170_2.png) [@mpniel](https://discuss.elastic.co/u/mpniel)
#### Post date: [January 29, 2024, 9:20pm UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/18 "2024-01-29T21:20:52Z")

</div>

‏updating the settings can be done in one command for a group of indices or you have to do it for each index?

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [January 30, 2024, 6:28am UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/19 "2024-01-30T06:28:23Z")

</div>

The example David provided updates the setting based on a index pattern with wildcard, so it is as you can see possible to update in groups.

---

<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: [February 27, 2024, 6:28am UTC](https://discuss.elastic.co/t/elasticsearch-v-7-5-how-to-delete-all-indexes-older-than-6-month-automatically/351036/20 "2024-02-27T06:28:45Z")

</div>

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