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
elastic#4864)

Closes elastic#4840

(cherry picked from commit 5a5e210)
  • Loading branch information
kvch authored and Tudor Golubenco committed Aug 25, 2017
1 parent b56c36c commit 9cb01d8
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 @@ -40,6 +40,8 @@ https://github.com/elastic/beats/compare/v6.0.0-beta1...master[Check the HEAD di
- Register kubernetes `field_format` matcher and remove logger in `Encode` API {pull}4888[4888]
- Fix go plugins not loaded when beat starts {pull}4799[4799]

- 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
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 @@ -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
Original file line number Diff line number Diff line change
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 9cb01d8

Please sign in to comment.