Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bryder/e9b2304f9702d0ee067c78aed8bb545b to your computer and use it in GitHub Desktop.
Save bryder/e9b2304f9702d0ee067c78aed8bb545b to your computer and use it in GitHub Desktop.
def add_template(cli_args, es):
template = {
'template': cli_args.elastic_index_prefix + '*',
'mappings': {
"_default_": {
'dynamic_templates': [
{ 'string_fields': {
'match': '*',
'match_mapping_type': 'string',
'mapping': {
'type': 'string', 'index': 'analyzed', 'omit_norms': False,
'fields': {
'raw': {'type': 'string', 'index': 'not_analyzed'}
}
}
}
}]
}
}
}
if cli_args.dry_run:
print "Would have added the mapping", json.dumps(template, indent=2)
else:
ies = elasticsearch.client.IndicesClient(es)
result = ies.put_template(name=cli_args.elastic_index_prefix, body=template)
log.debug("Template creation result: %s" % json.dumps(result))
es = elasticsearch.Elasticsearch(cli_args.elastic_url, sniff_on_start=True, sniff_on_connection_fail=True, retry_on_status=[503, 504, 401])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment