# How to delete logs from elasticsearch automatically

**URL:** <https://discuss.elastic.co/t/how-to-delete-logs-from-elasticsearch-automatically/284078>\
**Category:** Elasticsearch\
**Tags:** ilm-index-lifecycle-management, windows\
**Created:** [September 13, 2021, 1:37pm UTC](https://discuss.elastic.co/t/how-to-delete-logs-from-elasticsearch-automatically/284078 "2021-09-13T13:37:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SRIGURU\_VEL](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sriguru_vel/32/88656_2.png) [@SRIGURU\_VEL](https://discuss.elastic.co/u/SRIGURU_VEL)\
**Post date:** [September 13, 2021, 1:37pm UTC](https://discuss.elastic.co/t/how-to-delete-logs-from-elasticsearch-automatically/284078/1 "2021-09-13T13:37:55Z")

</div>

HI Experts,

We are using Elasticsearch 7.9 .  
We need to purge automatically the logs that we persist in Elasticsearch index based on a frequency/date

I need a proper guide for that.

thanks,  
Sriguruvel.

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [September 13, 2021, 1:47pm UTC](https://discuss.elastic.co/t/how-to-delete-logs-from-elasticsearch-automatically/284078/2 "2021-09-13T13:47:02Z")

</div>

You will need to create a Index Lifecycle Policy, check out this [part of the documentation](https://www.elastic.co/guide/en/elasticsearch/reference/7.9/index-lifecycle-management.html) about Index Lifecycle Management.

---

<div class="post-metadata">

**Author:** ![SRIGURU\_VEL](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sriguru_vel/32/88656_2.png) [@SRIGURU\_VEL](https://discuss.elastic.co/u/SRIGURU_VEL)\
**Post date:** [September 14, 2021, 6:16am UTC](https://discuss.elastic.co/t/how-to-delete-logs-from-elasticsearch-automatically/284078/3 "2021-09-14T06:16:41Z")

</div>

hi @leandrojmp ,

thanks for your reply.

thanks,  
sriguruvel.

---

<div class="post-metadata">

**Author:** ![SRIGURU\_VEL](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sriguru_vel/32/88656_2.png) [@SRIGURU\_VEL](https://discuss.elastic.co/u/SRIGURU_VEL)\
**Post date:** [September 22, 2021, 8:25am UTC](https://discuss.elastic.co/t/how-to-delete-logs-from-elasticsearch-automatically/284078/4 "2021-09-22T08:25:30Z")

</div>

hi @leandrojmp ,  
I tried below api . And also set in template mapping. but its not delete that index after 1 minute

> PUT \_ilm/policy/testpolicy  
> {  
> "policy": {  
> "phases": {  
> "hot": {  
> "actions": {  
> "rollover": {  
> "max\_age": "1m",  
> "max\_size": "50gb"  
> },  
> "set\_priority": {  
> "priority": 100  
> }  
> },  
> "min\_age": "0ms"  
> },  
> "delete": {  
> "min\_age": "1m",  
> "actions": {  
> "delete": {}  
> }  
> }  
> }  
> }  
> }

please give me correct API.  
thanks,  
Sriguruvel.

---

<div class="post-metadata">

**Author:** ![SRIGURU\_VEL](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sriguru_vel/32/88656_2.png) [@SRIGURU\_VEL](https://discuss.elastic.co/u/SRIGURU_VEL)\
**Post date:** [September 28, 2021, 6:58am UTC](https://discuss.elastic.co/t/how-to-delete-logs-from-elasticsearch-automatically/284078/5 "2021-09-28T06:58:45Z")

</div>

Hi experts,

I have done this automatic index delete process. thanks for giving suggestion .  
And I have another question,  
I created a policy for 1 minute(60s) And also I created 1 index with 1 document in 1st second.  
Then I created another document with same index in 30th second. But both documents are deleted in 60th second. But I need 1st created document will be deleted at 60th second and that 2nd one will be deleted at 90th second (30th second to 90th second = 1minute). Could you please help on this.

thanks ,  
Sriguruvel

---

<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:** [October 26, 2021, 6:59am UTC](https://discuss.elastic.co/t/how-to-delete-logs-from-elasticsearch-automatically/284078/6 "2021-10-26T06:59:28Z")

</div>

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