Skip to content

Commit

Permalink
[1.x] Move _meta section back inside mappings, in legacy templates. (#…
Browse files Browse the repository at this point in the history
…1186) (#1187)

Backports the following commits to 1.x:

* 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.
  • Loading branch information
Mathieu Martin authored Dec 10, 2020
1 parent ec42319 commit 5995da9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.next.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ Thanks, you're awesome :-) -->
* Added support in the generated Go source go for `wildcard`, `version`, and `constant_keyword` data types. #1050
* Added support for marking fields, field sets, or field reuse as beta in the documentation. #1051
* Added support for `constant_keyword`'s optional parameter `value`. #1112
* Added component templates for ECS field sets. #1156
* Added component templates for ECS field sets. #1156, #1186

#### Improvements

* Added a notice highlighting that the `tracing` fields are not nested under the
namespace `tracing.` #1162
* ES 6.x template data types will fallback to supported types. #1171, #1176
* ES 6.x template data types will fallback to supported types. #1171, #1176, #1186

#### Deprecated

Expand Down
6 changes: 3 additions & 3 deletions experimental/generated/elasticsearch/7/template.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"_meta": {
"version": "1.8.0-dev+exp"
},
"index_patterns": [
"try-ecs-*"
],
"mappings": {
"_meta": {
"version": "1.8.0-dev+exp"
},
"date_detection": false,
"dynamic_templates": [
{
Expand Down
6 changes: 3 additions & 3 deletions generated/elasticsearch/6/template.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"_meta": {
"version": "1.8.0-dev"
},
"index_patterns": [
"try-ecs-*"
],
"mappings": {
"_doc": {
"_meta": {
"version": "1.8.0-dev"
},
"date_detection": false,
"dynamic_templates": [
{
Expand Down
6 changes: 3 additions & 3 deletions generated/elasticsearch/7/template.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"_meta": {
"version": "1.8.0-dev"
},
"index_patterns": [
"try-ecs-*"
],
"mappings": {
"_meta": {
"version": "1.8.0-dev"
},
"date_detection": false,
"dynamic_templates": [
{
Expand Down
13 changes: 9 additions & 4 deletions scripts/generators/es_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,24 @@ 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:
es6_mappings_section = copy.deepcopy(mappings_section)
es6_type_fallback(es6_mappings_section['properties'])
mappings_section = copy.deepcopy(mappings_section)
es6_type_fallback(mappings_section['properties'])

# error.stack_trace needs special handling to set
# index: false and doc_values: false
error_stack_trace_mappings = es6_mappings_section['properties']['error']['properties']['stack_trace']
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)

template['mappings'] = {'_doc': es6_mappings_section}
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


Expand Down

0 comments on commit 5995da9

Please sign in to comment.