Skip to content

Commit

Permalink
Add minimal ES template functionality. (#12103)
Browse files Browse the repository at this point in the history
When loading a template without fields, create a minimal template only applying given configuration, without any default values for mappings and settings. This allows to create additional templates only defining specific values.
  • Loading branch information
simitt committed May 10, 2019
1 parent e4a427d commit 9ece0af
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 250 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ The list below covers the major changes between 7.0.0-rc2 and master only.
- Reduce idxmgmt.Supporter interface and rework export commands to reuse logic. {pull}11777[11777], {pull}12065[12065], {pull}12067[12067]
- Update urllib3 version to 1.24.2 {pull}11930[11930]
- Add libbeat/common/cleanup package. {pull}12134[12134]
- Only Load minimal template if no fields are provided. {pull}12103[12103]
12 changes: 12 additions & 0 deletions libbeat/template/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ func buildBody(tmpl *Template, config TemplateConfig, fields []byte) (common.Map
if config.Fields != "" {
return buildBodyFromFile(tmpl, config)
}
if fields == nil {
return buildMinimalTemplate(tmpl)
}
return buildBodyFromFields(tmpl, fields)
}

Expand Down Expand Up @@ -216,6 +219,15 @@ func buildBodyFromFields(tmpl *Template, fields []byte) (common.MapStr, error) {
return body, nil
}

func buildMinimalTemplate(tmpl *Template) (common.MapStr, error) {
logp.Debug("template", "Load minimal template")
body, err := tmpl.LoadMinimal()
if err != nil {
return nil, fmt.Errorf("error creating mimimal template: %v", err)
}
return body, nil
}

func esVersionParams(ver common.Version) map[string]string {
if ver.Major == 6 && ver.Minor == 7 {
return map[string]string{
Expand Down

0 comments on commit 9ece0af

Please sign in to comment.