# Automatically remove old reports

**URL:** <https://discuss.elastic.co/t/automatically-remove-old-reports/321201>\
**Category:** Elasticsearch\
**Created:** [December 14, 2022, 9:19am UTC](https://discuss.elastic.co/t/automatically-remove-old-reports/321201 "2022-12-14T09:19:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnJ\_M](https://avatars.discourse-cdn.com/v4/letter/j/a88e4f/32.png) [@JohnJ\_M](https://discuss.elastic.co/u/JohnJ_M)\
**Post date:** [December 14, 2022, 9:19am UTC](https://discuss.elastic.co/t/automatically-remove-old-reports/321201/1 "2022-12-14T09:19:00Z")

</div>

Hi the community.

I've alerters that generates multiple report once per week sent per mail automatically. Reports older than 2 weeks are not necessary and I want to be able to setup an automatic cleaning of those reports.

Is there an easy way to do it rather than manually doing the cleaning in the interface or launching manually a command?

---

<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 14, 2022, 10:11am UTC](https://discuss.elastic.co/t/automatically-remove-old-reports/321201/2 "2022-12-14T10:11:38Z")

</div>

The safest way to delete Reports from ES directly is:

```auto
POST /.reporting-<yyyy.mm.dd>/_delete_by_query
{ "query": { "match_all": {} } }

```

That deletes the documents, but not the index completely, making the mappings still correct for the index. That's the safe thing to do if you need to delete recent reports.

Thanks

---

<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 14, 2022, 11:46pm UTC](https://discuss.elastic.co/t/automatically-remove-old-reports/321201/3 "2022-12-14T23:46:22Z")

</div>

With respect to @dadiasish, delete by query is not the best approach.

If your reports are time based then you should look at suign [ILM](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-lifecycle-management.html).

---

<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:** [January 11, 2023, 11:46pm UTC](https://discuss.elastic.co/t/automatically-remove-old-reports/321201/4 "2023-01-11T23:46:34Z")

</div>

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