From 00fe6299242056ed5f3efc0bc5d79e1a52de22e0 Mon Sep 17 00:00:00 2001 From: Mathieu Martin Date: Thu, 10 Dec 2020 16:19:49 -0500 Subject: [PATCH] Move _meta section back inside mappings, in legacy templates. (#1186) This fixes an issue introduced by #1156, discovered in #1180. Composable templates support `_meta` at the template's root, but legacy templates don't. So we're just putting it back inside the mappings for legacy templates. This also fixes missing updates to the component template, after the introduction of wildcard in #1098. --- CHANGELOG.next.md | 2 +- experimental/generated/elasticsearch/7/template.json | 6 +++--- generated/elasticsearch/6/template.json | 6 +++--- generated/elasticsearch/7/template.json | 6 +++--- scripts/generators/es_template.py | 5 +++++ 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.next.md b/CHANGELOG.next.md index 5176db9d09..ca4fa584a4 100644 --- a/CHANGELOG.next.md +++ b/CHANGELOG.next.md @@ -30,7 +30,7 @@ Thanks, you're awesome :-) --> #### Added -* Added component templates for ECS field sets. #1156 +* Added component templates for ECS field sets. #1156, #1186 #### Improvements diff --git a/experimental/generated/elasticsearch/7/template.json b/experimental/generated/elasticsearch/7/template.json index 8ebea814f1..7e95828a42 100644 --- a/experimental/generated/elasticsearch/7/template.json +++ b/experimental/generated/elasticsearch/7/template.json @@ -1,11 +1,11 @@ { - "_meta": { - "version": "1.7.0+exp" - }, "index_patterns": [ "try-ecs-*" ], "mappings": { + "_meta": { + "version": "1.7.0+exp" + }, "date_detection": false, "dynamic_templates": [ { diff --git a/generated/elasticsearch/6/template.json b/generated/elasticsearch/6/template.json index 86990630de..62c033e096 100644 --- a/generated/elasticsearch/6/template.json +++ b/generated/elasticsearch/6/template.json @@ -1,12 +1,12 @@ { - "_meta": { - "version": "1.7.0" - }, "index_patterns": [ "try-ecs-*" ], "mappings": { "_doc": { + "_meta": { + "version": "1.7.0" + }, "date_detection": false, "dynamic_templates": [ { diff --git a/generated/elasticsearch/7/template.json b/generated/elasticsearch/7/template.json index b3e998015f..8341531f01 100644 --- a/generated/elasticsearch/7/template.json +++ b/generated/elasticsearch/7/template.json @@ -1,11 +1,11 @@ { - "_meta": { - "version": "1.7.0" - }, "index_patterns": [ "try-ecs-*" ], "mappings": { + "_meta": { + "version": "1.7.0" + }, "date_detection": false, "dynamic_templates": [ { diff --git a/scripts/generators/es_template.py b/scripts/generators/es_template.py index b221cb5531..81e35e5d6e 100644 --- a/scripts/generators/es_template.py +++ b/scripts/generators/es_template.py @@ -184,10 +184,15 @@ def template_settings(es_version, ecs_version, mappings_section, template_settin template = json.load(f) else: template = default_template_settings(ecs_version) + if es_version == 6: 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') + return template