From 3b7c12168f387213ad291edc13672bd6cd9a569d Mon Sep 17 00:00:00 2001 From: Eric Beahan Date: Mon, 14 Dec 2020 13:22:12 -0600 Subject: [PATCH] Conditional handling in es_template.template_settings (#1191) --- 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