Warm tip: This article is reproduced from stackoverflow.com, please click
elasticsearch elasticsearch-curator

delete indices except newest

发布于 2020-03-31 23:01:29

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.

Questioner
RFI
Viewed
86
Val 2019-09-19 22:17

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.