Created
June 10, 2021 07:21
-
-
Save baybatu/3012dc91924c35a5d7b8a09f54dc3a49 to your computer and use it in GitHub Desktop.
delete index by pattern in Elasticsearch with Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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