Skip to content

Commit

Permalink
libbeat: change deprecated _default_ mapping to doc in index templates (
Browse files Browse the repository at this point in the history
#4864)

Closes #4840
  • Loading branch information
kvch authored and tsg committed Aug 10, 2017
1 parent f2d6035 commit 5a5e210
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ https://github.com/elastic/beats/compare/v6.0.0-beta1...master[Check the HEAD di
*Affecting all Beats*
- Fix go plugins not loaded when beat starts {pull}4799[4799]

- Eliminate deprecated _default_ mapping in 6.x {pull}4864[4864]

*Auditbeat*

- Fix `file.max_file_size` config option for the audit file metricset. {pull}4796[4796]
Expand Down
2 changes: 1 addition & 1 deletion libbeat/ml-importer/importer_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const sampleDatafeed = `
"filebeat-*"
],
"types": [
"_default_",
"doc",
"log"
],
"query": {
Expand Down
6 changes: 3 additions & 3 deletions libbeat/template/load_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func TestTemplateSettings(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, val.(string), "1")

val, err = templateJSON.GetValue("mappings._default_._source.enabled")
val, err = templateJSON.GetValue("mappings.doc._source.enabled")
assert.NoError(t, err)
assert.Equal(t, val.(bool), false)

Expand Down Expand Up @@ -255,7 +255,7 @@ func TestOverwrite(t *testing.T) {

// Overwrite was not enabled, so the first version should still be there
templateJSON := getTemplate(t, client, templateName)
_, err = templateJSON.GetValue("mappings._default_._source.enabled")
_, err = templateJSON.GetValue("mappings.doc._source.enabled")
assert.Error(t, err)

// Load template again, this time with custom settings AND overwrite: true
Expand All @@ -276,7 +276,7 @@ func TestOverwrite(t *testing.T) {

// Overwrite was enabled, so the custom setting should be there
templateJSON = getTemplate(t, client, templateName)
val, err := templateJSON.GetValue("mappings._default_._source.enabled")
val, err := templateJSON.GetValue("mappings.doc._source.enabled")
assert.NoError(t, err)
assert.Equal(t, val.(bool), false)

Expand Down
12 changes: 10 additions & 2 deletions libbeat/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,17 @@ func (t *Template) generate(properties common.MapStr, dynamicTemplates []common.
}
indexSettings.DeepUpdate(t.settings.Index)

var mappingName string
if t.esVersion.Major >= 6 {
mappingName = "doc"
} else {
mappingName = "_default_"
}

// Load basic structure
basicStructure := common.MapStr{
"mappings": common.MapStr{
"_default_": common.MapStr{
mappingName: common.MapStr{
"_meta": common.MapStr{
"version": t.beatVersion.String(),
},
Expand All @@ -117,7 +124,8 @@ func (t *Template) generate(properties common.MapStr, dynamicTemplates []common.
}

if len(t.settings.Source) > 0 {
basicStructure.Put("mappings._default_._source", t.settings.Source)
key := fmt.Sprintf("mappings.%s._source", mappingName)
basicStructure.Put(key, t.settings.Source)
}

// ES 6 moved from template to index_patterns: https://github.com/elastic/elasticsearch/pull/21009
Expand Down

0 comments on commit 5a5e210

Please sign in to comment.