# How to delete index document after 30 days?

**URL:** <https://discuss.elastic.co/t/how-to-delete-index-document-after-30-days/358761>\
**Category:** Elastic Search\
**Created:** [May 5, 2024, 4:30pm UTC](https://discuss.elastic.co/t/how-to-delete-index-document-after-30-days/358761 "2024-05-05T16:30:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kishor\_Patidar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kishor_patidar/32/134134_2.png) [@Kishor\_Patidar](https://discuss.elastic.co/u/Kishor_Patidar)\
**Post date:** [May 5, 2024, 4:30pm UTC](https://discuss.elastic.co/t/how-to-delete-index-document-after-30-days/358761/1 "2024-05-05T16:30:26Z")

</div>

I'm working with AWS OpenSearch and tried to implement an Index State Management (ISM) policy to delete documents that are older than 30 days. However, the policy ended up deleting the entire index, not just the aged documents. I also attempted to use `_delete_by_query`, which worked as expected, but I'm looking for a different approach.

Is there an alternative way to automatically delete documents once they've reached 30 days old? Also, is there a way to set a time-to-live (TTL) on individual documents to control their lifespan?

---

<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:** [May 5, 2024, 4:30pm UTC](https://discuss.elastic.co/t/how-to-delete-index-document-after-30-days/358761/2 "2024-05-05T16:30:26Z")

</div>

OpenSearch/OpenDistro are AWS run products and differ from the original Elasticsearch and Kibana products that Elastic builds and maintains. You may need to contact them directly for further assistance. See [What is OpenSearch and the OpenSearch Dashboard? | Elastic](https://www.elastic.co/elasticsearch/opensearch) for more details.

(This is an automated response from your friendly Elastic bot. Please report this post if you have any suggestions or concerns :elasticheart: )

---

<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:** [May 5, 2024, 5:19pm UTC](https://discuss.elastic.co/t/how-to-delete-index-document-after-30-days/358761/3 "2024-05-05T17:19:47Z")

</div>

> [@Kishor\_Patidar](#):
>
> Is there an alternative way to automatically delete documents once they've reached 30 days old? Also, is there a way to set a time-to-live (TTL) on individual documents to control their lifespan?

As far as I know the answer is no. You do indeed need to use delete by query. This is as the bot pointed out not the correct forum, so you need to ask the OpenSearch community as they may have something I am not aware of.

---

<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:** [May 5, 2024, 5:34pm UTC](https://discuss.elastic.co/t/how-to-delete-index-document-after-30-days/358761/4 "2024-05-05T17:34:59Z")

</div>

Did you look at [Cloud by Elastic](https://www.elastic.co/cloud), also available if needed from [AWS Marketplace](https://aws.amazon.com/marketplace/pp/Elasticsearch-Inc-Elasticsearch-Service-on-Elastic/B01N6YCISK), [Azure Marketplace](https://azuremarketplace.microsoft.com/en-us/marketplace/apps/elastic.ec-azure?tab=Overview) and [Google Cloud Marketplace](https://console.cloud.google.com/marketplace/details/endpoints/elasticsearch-service.gcpmarketplace.elastic.co)?

Cloud by elastic is one way to have access to **all features** , all managed by us. Think about what is there yet like Vector Search, Security, Monitoring, Reporting, ES|QL, Canvas, Maps UI, Alerting and built-in solutions named [Observability](https://www.elastic.co/observability), [Security](https://www.elastic.co/security) and what is coming next 🙂 ...

---

<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:** [June 2, 2024, 5:35pm UTC](https://discuss.elastic.co/t/how-to-delete-index-document-after-30-days/358761/5 "2024-06-02T17:35:36Z")

</div>

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