Skip to content

Instantly share code, notes, and snippets.

@eht16
Created March 21, 2018 15:18
Show Gist options
  • Save eht16/135e3e3e21d5a0506a909febf574fd07 to your computer and use it in GitHub Desktop.
Save eht16/135e3e3e21d5a0506a909febf574fd07 to your computer and use it in GitHub Desktop.
diff --git a/elastalert/create_index.py b/elastalert/create_index.py
index ae85940..5d8ea02 100644
--- a/elastalert/create_index.py
+++ b/elastalert/create_index.py
@@ -63,6 +63,7 @@ def main():
data = yaml.load(config_file)
host = args.host if args.host else data.get('es_host')
port = args.port if args.port else data.get('es_port')
+ index_settings = data.get('index_settings')
username = args.username if args.username else data.get('es_username')
password = args.password if args.password else data.get('es_password')
url_prefix = args.url_prefix if args.url_prefix is not None else data.get('es_url_prefix', '')
@@ -78,6 +79,7 @@ def main():
else:
username = args.username if args.username else None
password = args.password if args.password else None
+ index_settings = None
aws_region = args.aws_region
host = args.host if args.host else raw_input('Enter Elasticsearch host: ')
port = args.port if args.port else int(raw_input('Enter Elasticsearch port: '))
@@ -124,6 +126,15 @@ def main():
ca_certs=ca_certs,
client_key=client_key)
+ if index_settings is not None:
+ settings = {'settings': {'index': {}}}
+ if index_settings["shards"] is not None:
+ settings["settings"]["index"]["number_of_shards"] = index_settings["shards"]
+ if index_settings["replicas"] is not None:
+ settings["settings"]["index"]["number_of_replicas"] = index_settings["replicas"]
+ else:
+ settings = None
+
esversion = es.info()["version"]["number"]
print("Elastic Version:" + esversion.split(".")[0])
elasticversion = int(esversion.split(".")[0])
@@ -159,13 +170,13 @@ def main():
return None
if (elasticversion > 5):
- es.indices.create(index)
- es.indices.create(index+'_status')
- es.indices.create(index+'_silence')
- es.indices.create(index+'_error')
- es.indices.create(index+'_past')
+ es.indices.create(index, body=settings)
+ es.indices.create(index+'_status', body=settings)
+ es.indices.create(index+'_silence', body=settings)
+ es.indices.create(index+'_error', body=settings)
+ es.indices.create(index+'_past', body=settings)
else:
- es.indices.create(index)
+ es.indices.create(index, body=settings)
# To avoid a race condition. TODO: replace this with a real check
time.sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment