Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set shards and replicas settings for index creation #1201

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ writeback_index: elastalert_status
# sending the alert until this time period has elapsed
alert_time_limit:
days: 2

# Set shards and replicas settings for index creation
#index_settings:
# shards: 1
# replicas: 0
13 changes: 12 additions & 1 deletion elastalert/create_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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 = data.get('es_username')
password = data.get('es_password')
url_prefix = args.url_prefix if args.url_prefix is not None else data.get('es_url_prefix', '')
Expand All @@ -67,6 +68,7 @@ def main():
else:
username = None
password = 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: '))
Expand Down Expand Up @@ -103,6 +105,15 @@ def main():
url_prefix=url_prefix,
send_get_body_as=send_get_body_as)

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

silence_mapping = {'silence': {'properties': {'rule_name': {'index': 'not_analyzed', 'type': 'string'},
'until': {'type': 'date', 'format': 'dateOptionalTime'},
'@timestamp': {'format': 'dateOptionalTime', 'type': 'date'}}}}
Expand Down Expand Up @@ -132,7 +143,7 @@ def main():
print('Index ' + index + ' already exists. Skipping index creation.')
return None

es.indices.create(index)
es.indices.create(index=index, body=settings)
# To avoid a race condition. TODO: replace this with a real check
time.sleep(2)
es.indices.put_mapping(index=index, doc_type='elastalert', body=es_mapping)
Expand Down