Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick #4864 to 6.0: Change deprecated _default_ mapping to doc in index templates #5019

Merged
merged 1 commit into from
Aug 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty line here probably coming from rebase?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, i would ignore that for now, I'm doing reformatting when closing the the CHANGELOG anyway.

- 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