Created
August 25, 2015 16:30
-
-
Save rstruber/10a036d9fdd1191121af to your computer and use it in GitHub Desktop.
Example of how to use curator and elasticsearch python api to update index settings
This file contains hidden or 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
import elasticsearch | |
import curator | |
import json | |
client = elasticsearch.Elasticsearch() | |
indices = curator.get_indices(client) | |
# Filter anything older than or equal to 3 days | |
_filter = curator.build_filter(kindOf='newer_than', value=3, time_unit='days', timestring='%Y.%m.%d') | |
indices = curator.apply_filter(indices, **_filter) | |
# Filter anything newer than or equal to 1 day | |
_filter = curator.build_filter(kindOf='older_than', value=1, time_unit='days', timestring='%Y.%m.%d') | |
indices = curator.apply_filter(indices, **_filter) | |
for index in indices: | |
put = client.indices.put_settings( | |
index=index, | |
body='''{ | |
"index": { | |
"refresh_interval": -1, | |
"blocks.write": true | |
} | |
}''', | |
ignore_unavailable=True | |
) | |
if 'acknowledged' not in put or put['acknowledged'] != True: | |
raise Exception('Failed to update index: %s\n\n%s' % (index, json.dumps(put))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment