1

How do I define default record ttl for an index?

I read through OpenSearch's create index docs, but can't find how to define default ttl for an index.

quzhi65222714
  • 334
  • 3
  • 9

1 Answers1

1

EDIT: The _ttl mappings have been removed. As a replacement for _ttl mappings, we recommend using ILM to create time-based indices. https://www.elastic.co/guide/en/elasticsearch/reference/8.7/mapping-ttl-field.html

TTL = index retention period in Elasticsearch/Opensearch.

UPDATE: You can use delete by query with time range filter.

POST my-index-000001/_delete_by_query?routing=1
{
  "query": {
    "range" : {
        "field_name" : {
           "lte" : "now-10d"
        }
    }
  }
}

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html

Musab Dogan
  • 1,811
  • 1
  • 6
  • 8
  • Thanks for answering this! What I am looking for is record ttl, not index ttl. I don't want to delete the index, but delete a record after a certain period of time. – quzhi65222714 Apr 26 '23 at 00:20
  • You can use _delete_by_query API call. – Musab Dogan Apr 26 '23 at 07:37
  • _delete_by_query is manual delete. I remember ElasticSearch has a _ttl field, but I am not sure whether OpenSearch support it. – quzhi65222714 May 03 '23 at 16:07
  • 1
    `The _ttl mappings have been removed. As a replacement for _ttl mappings, we recommend using ILM to create time-based indices.` https://www.elastic.co/guide/en/elasticsearch/reference/8.7/mapping-ttl-field.html – Musab Dogan May 04 '23 at 08:39