From 78573516a15cd183d35727a85bdca71ce57ed553 Mon Sep 17 00:00:00 2001 From: Eric Beahan Date: Mon, 14 Dec 2020 13:48:24 -0600 Subject: [PATCH] [1.x] Conditional handling in es_template.template_settings (#1191) (#1192) --- scripts/generators/es_template.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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