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

allow forcing dynamic object type mapping #6691

Merged
merged 3 commits into from
Mar 30, 2018
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
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di
- Add logging when monitoring cannot connect to Elasticsearch. {pull}6365[6365]
- Rename beat.cpu.*.time metrics to beat.cpu.*.time.ms. {pull}6449[6449]
- Mark `system.syslog.message` and `system.auth.message` as `text` instead of `keyword`. {pull}6589[6589]
- Allow override of dynamic template `match_mapping_type` for fields with object_type. {pull}6691[6691]

*Auditbeat*

Expand Down
33 changes: 17 additions & 16 deletions libbeat/common/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@ import (
type Fields []Field

type Field struct {
Name string `config:"name"`
Type string `config:"type"`
Description string `config:"description"`
Format string `config:"format"`
ScalingFactor int `config:"scaling_factor"`
Fields Fields `config:"fields"`
MultiFields Fields `config:"multi_fields"`
ObjectType string `config:"object_type"`
Enabled *bool `config:"enabled"`
Analyzer string `config:"analyzer"`
SearchAnalyzer string `config:"search_analyzer"`
Norms bool `config:"norms"`
Dynamic DynamicType `config:"dynamic"`
Index *bool `config:"index"`
DocValues *bool `config:"doc_values"`
CopyTo string `config:"copy_to"`
Name string `config:"name"`
Type string `config:"type"`
Description string `config:"description"`
Format string `config:"format"`
ScalingFactor int `config:"scaling_factor"`
Fields Fields `config:"fields"`
MultiFields Fields `config:"multi_fields"`
ObjectType string `config:"object_type"`
ObjectTypeMappingType string `config:"object_type_mapping_type"`
Enabled *bool `config:"enabled"`
Analyzer string `config:"analyzer"`
SearchAnalyzer string `config:"search_analyzer"`
Norms bool `config:"norms"`
Dynamic DynamicType `config:"dynamic"`
Index *bool `config:"index"`
DocValues *bool `config:"doc_values"`
CopyTo string `config:"copy_to"`

// Kibana specific
Analyzed *bool `config:"analyzed"`
Expand Down
13 changes: 10 additions & 3 deletions libbeat/template/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ func (p *Processor) array(f *common.Field) common.MapStr {
func (p *Processor) object(f *common.Field) common.MapStr {
dynProperties := getDefaultProperties(f)

matchType := func(onlyType string) string {
if f.ObjectTypeMappingType != "" {
return f.ObjectTypeMappingType
}
return onlyType
}

switch f.ObjectType {
case "text":
dynProperties["type"] = "text"
Expand All @@ -208,13 +215,13 @@ func (p *Processor) object(f *common.Field) common.MapStr {
dynProperties["type"] = "string"
dynProperties["index"] = "analyzed"
}
addDynamicTemplate(f, dynProperties, "string")
addDynamicTemplate(f, dynProperties, matchType("string"))
case "long":
dynProperties["type"] = f.ObjectType
addDynamicTemplate(f, dynProperties, "long")
addDynamicTemplate(f, dynProperties, matchType("long"))
case "keyword":
dynProperties["type"] = f.ObjectType
addDynamicTemplate(f, dynProperties, "string")
addDynamicTemplate(f, dynProperties, matchType("string"))
}

properties := getDefaultProperties(f)
Expand Down
26 changes: 26 additions & 0 deletions libbeat/template/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,32 @@ func TestDynamicTemplate(t *testing.T) {
},
},
},
{
field: common.Field{
Type: "object", ObjectType: "long", ObjectTypeMappingType: "futuretype",
Path: "language", Name: "english",
},
expected: common.MapStr{
"language.english": common.MapStr{
"mapping": common.MapStr{"type": "long"},
"match_mapping_type": "futuretype",
"path_match": "language.english.*",
},
},
},
{
field: common.Field{
Type: "object", ObjectType: "long", ObjectTypeMappingType: "*",
Path: "language", Name: "english",
},
expected: common.MapStr{
"language.english": common.MapStr{
"mapping": common.MapStr{"type": "long"},
"match_mapping_type": "*",
"path_match": "language.english.*",
},
},
},
{
field: common.Field{
Type: "object", ObjectType: "long",
Expand Down