diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 174eec9abf7..fa57f9640e3 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -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* diff --git a/libbeat/common/field.go b/libbeat/common/field.go index 7a4b7e5a88b..3eadc275403 100644 --- a/libbeat/common/field.go +++ b/libbeat/common/field.go @@ -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"` diff --git a/libbeat/template/processor.go b/libbeat/template/processor.go index 388fcda758e..b98bca748f2 100644 --- a/libbeat/template/processor.go +++ b/libbeat/template/processor.go @@ -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" @@ -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) diff --git a/libbeat/template/processor_test.go b/libbeat/template/processor_test.go index c3a8fc0d88d..d83c251feaf 100644 --- a/libbeat/template/processor_test.go +++ b/libbeat/template/processor_test.go @@ -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",