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.
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
example_dev_*
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.
What if the index fits the pattern and also the age, but is the only index? In that case I would not want it deleted.
How are your indexes named? if you have all your data in a single index but you only want to delete old data from that index, then Curator won't help you, you need a solution like this one instead: stackoverflow.com/a/57975075/4604579
Indexes are named: example_dev_1_v{increment}, for example: example_dev_1_v1, example_dev_1_v5, example_dev_2_v1, example_dev_2_v2
The question is do you need to always delete entire indexes, or sometimes only part of the index?
I need to delete the entire index that fits pattern: example_dev_1_v... except for the latest version. Note that the value after the
v
may or may not be the highest value for the latest version. Is it not possible to use Curator to delete an index based on the creation date, except for the latest one?