Skip to content

Commit 7857351

Browse files
authored
[1.x] Conditional handling in es_template.template_settings (#1191) (#1192)
1 parent 0e94d2d commit 7857351

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

scripts/generators/es_template.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,23 @@ def template_settings(es_version, ecs_version, mappings_section, template_settin
198198
es6_type_fallback(mappings_section['properties'])
199199

200200
# error.stack_trace needs special handling to set
201-
# index: false and doc_values: false
202-
error_stack_trace_mappings = mappings_section['properties']['error']['properties']['stack_trace']
203-
error_stack_trace_mappings.setdefault('index', False)
204-
error_stack_trace_mappings.setdefault('doc_values', False)
201+
# index: false and doc_values: false if the field
202+
# is present in the mappings
203+
try:
204+
error_stack_trace_mappings = mappings_section['properties']['error']['properties']['stack_trace']
205+
error_stack_trace_mappings.setdefault('index', False)
206+
error_stack_trace_mappings.setdefault('doc_values', False)
207+
except KeyError:
208+
pass
205209

206210
template['mappings'] = {'_doc': mappings_section}
207211
else:
208212
template['mappings'] = mappings_section
209213

210214
# _meta can't be at template root in legacy templates, so moving back to mappings section
211-
mappings_section['_meta'] = template.pop('_meta')
215+
# if present
216+
if '_meta' in template:
217+
mappings_section['_meta'] = template.pop('_meta')
212218

213219
return template
214220

0 commit comments

Comments
 (0)