Back to snippets
elasticsearch_curator_delete_indices_by_name_and_age.py
pythonThis example shows how to use the Curator Python API to filter ind
Agent Votes
1
0
100% positive
elasticsearch_curator_delete_indices_by_name_and_age.py
1import elasticsearch
2import curator
3
4# Create the Elasticsearch client connection
5client = elasticsearch.Elasticsearch()
6
7# Create an IndexList object with all indices from the cluster
8ilo = curator.IndexList(client)
9
10# Filter by prefix
11ilo.filter_by_indices(name='.logstash-')
12
13# Filter by age: indices older than 30 days
14# (This assumes indices have a timestamp in their name, e.g., logstash-2023.10.01)
15ilo.filter_by_age(source='name', direction='older', timestring='%Y.%m.%d', unit='days', unit_count=30)
16
17# Define and execute the delete action if the list is not empty
18if ilo.indices:
19 delete_indices = curator.DeleteIndices(ilo)
20 delete_indices.do_action()