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) (#5019)

Closes #4840

(cherry picked from commit 5a5e210)
  • Loading branch information
tsg authored and ruflin committed Aug 28, 2017
1 parent 1000dc5 commit f430c57
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Expand Up @@ -41,6 +41,8 @@ https://github.com/elastic/beats/compare/v6.0.0-beta1...master[Check the HEAD di
- Fix go plugins not loaded when beat starts {pull}4799[4799]
- Add support for `initContainers` in `add_kubernetes_metadata` processor. {issue}4825[4825]

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

*Auditbeat*

*Filebeat*
Expand Down
2 changes: 1 addition & 1 deletion libbeat/ml-importer/importer_integration_test.go
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
Expand Up @@ -200,7 +200,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 @@ -258,7 +258,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 @@ -279,7 +279,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
Expand Up @@ -146,10 +146,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 @@ -165,7 +172,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 f430c57

Please sign in to comment.