Skip to content

Commit

Permalink
Add support for keyword multifields
Browse files Browse the repository at this point in the history
Before a multifield was only possible if the top level field was text. Now it can also be keyword.
  • Loading branch information
ruflin committed May 22, 2018
1 parent 9f499c0 commit 9a8fb7a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ https://github.com/elastic/beats/compare/v6.2.3...master[Check the HEAD diff]
- Add Kibana module with log fileset. {pull}7052[7052]
- Add default_fields to Elasticsearch template when connecting to Elasticsearch >= 7.0. {pull}7015[7015]
- Add support for loading a template.json file directly instead of using fields.yml. {pull}7039[7039]
- Add support for keyword multifields in field.yml. {pull}7131[7131]

*Auditbeat*

Expand Down
7 changes: 7 additions & 0 deletions libbeat/template/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ func (p *Processor) keyword(f *common.Field) common.MapStr {
property["ignore_above"] = 1024
property["index"] = "not_analyzed"
}

if len(f.MultiFields) > 0 {
fields := common.MapStr{}
p.Process(f.MultiFields, "", fields)
property["fields"] = fields
}

return property
}

Expand Down
31 changes: 31 additions & 0 deletions libbeat/template/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,37 @@ func TestProcessor(t *testing.T) {
},
},
},
{
output: p.keyword(&common.Field{Type: "keyword", MultiFields: common.Fields{common.Field{Name: "analyzed", Type: "text", Norms: true}}}),
expected: common.MapStr{
"type": "keyword",
"ignore_above": 1024,
"fields": common.MapStr{
"analyzed": common.MapStr{
"type": "text",
},
},
},
},
{
output: p.text(&common.Field{Type: "text", MultiFields: common.Fields{
common.Field{Name: "raw", Type: "keyword"},
common.Field{Name: "indexed", Type: "text"},
}, Norms: true}),
expected: common.MapStr{
"type": "text",
"fields": common.MapStr{
"raw": common.MapStr{
"type": "keyword",
"ignore_above": 1024,
},
"indexed": common.MapStr{
"type": "text",
"norms": false,
},
},
},
},
{
output: p.text(&common.Field{Type: "text", MultiFields: common.Fields{
common.Field{Name: "raw", Type: "keyword"},
Expand Down

0 comments on commit 9a8fb7a

Please sign in to comment.