Skip to content

Commit

Permalink
Add ip fields to default_field in Elasticsearch template (elastic#11035)
Browse files Browse the repository at this point in the history
Pasting an IP into Kibana's KQL bar currently yields no results - even when there are plenty of documents with that IP. The reason is that IP fields are currently not included in the default_field configuration of the generated template.

This adds them.

For Auditbeat, this adds 9 fields. For the others, it looks like 16 for Metricbeat, 15 for Filebeat, 17 for Packetbeat.

(cherry picked from commit eee127c)
  • Loading branch information
Christoph Wurm committed Mar 7, 2019
1 parent 1013672 commit d99a6f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ https://github.com/elastic/beats/compare/v6.6.0...6.x[Check the HEAD diff]
- Add support for index lifecycle management (beta). {pull}7963[7963]
- Always include Pod UID as part of Pod metadata. {pull]9517[9517]
- Release Jolokia autodiscover as GA. {pull}9706[9706]
- Add ip fields to default_field in Elasticsearch template. {pull}11035[11035]

*Auditbeat*

Expand Down
34 changes: 16 additions & 18 deletions libbeat/template/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,29 @@ func (p *Processor) Process(fields common.Fields, path string, output common.Map
mapping = p.other(&field)
}

switch field.Type {
case "", "keyword", "text", "ip":
addToDefaultFields(&field)
}

if len(mapping) > 0 {
output.Put(common.GenerateKey(field.Name), mapping)
}
}
return nil
}

func addToDefaultFields(f *common.Field) {
fullName := f.Name
if f.Path != "" {
fullName = f.Path + "." + f.Name
}

if f.Index == nil || (f.Index != nil && *f.Index) {
defaultFields = append(defaultFields, fullName)
}
}

func (p *Processor) other(f *common.Field) common.MapStr {
property := getDefaultProperties(f)
if f.Type != "" {
Expand Down Expand Up @@ -172,15 +188,6 @@ func (p *Processor) ip(f *common.Field) common.MapStr {
func (p *Processor) keyword(f *common.Field) common.MapStr {
property := getDefaultProperties(f)

fullName := f.Name
if f.Path != "" {
fullName = f.Path + "." + f.Name
}

if f.Index == nil || (f.Index != nil && *f.Index) {
defaultFields = append(defaultFields, fullName)
}

property["type"] = "keyword"

switch f.IgnoreAbove {
Expand Down Expand Up @@ -208,15 +215,6 @@ func (p *Processor) keyword(f *common.Field) common.MapStr {
func (p *Processor) text(f *common.Field) common.MapStr {
properties := getDefaultProperties(f)

fullName := f.Name
if f.Path != "" {
fullName = f.Path + "." + f.Name
}

if f.Index == nil || (f.Index != nil && *f.Index) {
defaultFields = append(defaultFields, fullName)
}

properties["type"] = "text"

if p.EsVersion.IsMajor(2) {
Expand Down

0 comments on commit d99a6f5

Please sign in to comment.