Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
delete index by pattern in Elasticsearch with Python
# usage
# python delete-index-by-pattern-in-es.py http://ES_HOST:9200 my-es-index-*
# indexes matched with pattern you entered will be deleted
from elasticsearch import Elasticsearch
import sys
es_host = sys.argv[1]
index_pattern = sys.argv[2]
print(f"es_host:{es_host} ; index_pattern:{index_pattern}")
es = Elasticsearch([es_host])
for index_name in es.indices.get(index_pattern):
print(f"Trying to delete es index : {index_name}")
res = es.indices.delete(index=index_name, ignore=[400, 404])
print(f"IndexName:{index_name} ; ES response:{res}")
print("DONE")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment