Search code examples
elasticsearchelasticsearch-curator

Elasticsearch Curator - delete indices except newest


Using Elasticsearch curator, how do I delete all indices matching a pattern, except for the newest?

I tried using filtertype: age but it does not seem to do what I need.


Solution

  • You need two filters: pattern (to match the indexes you want to delete) and age (to specify the age of the indexes to delete).

    For instance the Curator configuration below is configured to delete

    • indexes named example_dev_*
    • and which are older than 10 days

    Configuration:

    actions:
      1:
        action: delete_indices
        description: >-
          Delete indices older than 10 days (based on index name), for example_dev_
          prefixed indices.
        options:
          ignore_empty_list: True
          disable_action: True
        filters:
        - filtertype: pattern
          kind: prefix
          value: example_dev_
        - filtertype: age
          source: creation_date
          direction: older
          unit: days
          unit_count: 10
        - filtertype: count
          count: 1
    

    You need to adapt both filter conditions to your needs, but that would achieve what you expect.