diff --git a/scripts/generators/es_template.py b/scripts/generators/es_template.py index fb45800dce..386fd6e49b 100644 --- a/scripts/generators/es_template.py +++ b/scripts/generators/es_template.py @@ -198,17 +198,23 @@ def template_settings(es_version, ecs_version, mappings_section, template_settin es6_type_fallback(mappings_section['properties']) # error.stack_trace needs special handling to set - # index: false and doc_values: false - error_stack_trace_mappings = mappings_section['properties']['error']['properties']['stack_trace'] - error_stack_trace_mappings.setdefault('index', False) - error_stack_trace_mappings.setdefault('doc_values', False) + # index: false and doc_values: false if the field + # is present in the mappings + try: + error_stack_trace_mappings = mappings_section['properties']['error']['properties']['stack_trace'] + error_stack_trace_mappings.setdefault('index', False) + error_stack_trace_mappings.setdefault('doc_values', False) + except KeyError: + pass template['mappings'] = {'_doc': mappings_section} else: template['mappings'] = mappings_section # _meta can't be at template root in legacy templates, so moving back to mappings section - mappings_section['_meta'] = template.pop('_meta') + # if present + if '_meta' in template: + mappings_section['_meta'] = template.pop('_meta') return template