Skip to content

Commit

Permalink
libbeat: Don't force an ignore_above limit in wildcard fields
Browse files Browse the repository at this point in the history
Modifies libbeat's template processor to stop hardcoding a default
`ignore_above` limit of 1024 on wildcard fields. This behavior was
inherited from keyword fields.

Closes elastic#30096
  • Loading branch information
adriansr committed Mar 3, 2022
1 parent a28c413 commit 2d540a0
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 37 deletions.
9 changes: 4 additions & 5 deletions libbeat/template/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,10 @@ func (p *Processor) wildcard(f *mapping.Field, analyzers common.MapStr) common.M

property["type"] = "wildcard"

switch f.IgnoreAbove {
case 0: // Use libbeat default
property["ignore_above"] = defaultIgnoreAbove
case -1: // Use ES default
default: // Use user value
/* For wildcard fields, unlike keyword, don't force a default ignore_above limit.
The default in ES will be used unless an explicit limit is set.
*/
if f.IgnoreAbove > 0 {
property["ignore_above"] = f.IgnoreAbove
}

Expand Down
95 changes: 63 additions & 32 deletions libbeat/template/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,46 +805,77 @@ func TestProcessWildcardOSS(t *testing.T) {
}

func TestProcessWildcardElastic(t *testing.T) {
// Test common fields are combined even if they come from different objects
fields := mapping.Fields{
mapping.Field{
Name: "test",
Type: "group",
Fields: mapping.Fields{
for _, test := range []struct {
title string
fields mapping.Fields
expected common.MapStr
}{
{
title: "default",
fields: mapping.Fields{
mapping.Field{
Name: "one",
Type: "wildcard",
Name: "test",
Type: "group",
Fields: mapping.Fields{
mapping.Field{
Name: "one",
Type: "wildcard",
},
},
},
},
expected: common.MapStr{
"test": common.MapStr{
"properties": common.MapStr{
"one": common.MapStr{
"type": "wildcard",
},
},
},
},
},
}

output := common.MapStr{}
analyzers := common.MapStr{}
version, err := common.NewVersion("8.0.0")
if err != nil {
t.Fatal(err)
}

p := Processor{EsVersion: *version, ElasticLicensed: true}
err = p.Process(fields, nil, output, analyzers)
if err != nil {
t.Fatal(err)
}

// Make sure fields without a name are skipped during template generation
expectedOutput := common.MapStr{
"test": common.MapStr{
"properties": common.MapStr{
"one": common.MapStr{
"ignore_above": 1024,
"type": "wildcard",
{
title: "explicit ignore_above",
fields: mapping.Fields{
mapping.Field{
Name: "test",
Type: "group",
Fields: mapping.Fields{
mapping.Field{
Name: "one",
Type: "wildcard",
IgnoreAbove: 4096,
},
},
},
},
expected: common.MapStr{
"test": common.MapStr{
"properties": common.MapStr{
"one": common.MapStr{
"ignore_above": 4096,
"type": "wildcard",
},
},
},
},
},
} {
t.Run(test.title, func(t *testing.T) {
output := common.MapStr{}
analyzers := common.MapStr{}
version, err := common.NewVersion("8.0.0")
if err != nil {
t.Fatal(err)
}
p := Processor{EsVersion: *version, ElasticLicensed: true}
err = p.Process(test.fields, nil, output, analyzers)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, test.expected, output)
})
}

assert.Equal(t, expectedOutput, output)
}

func TestProcessWildcardPreSupport(t *testing.T) {
Expand Down

0 comments on commit 2d540a0

Please sign in to comment.