in libbeat/template/processor.go [67:175]
func (p *Processor) Process(fields mapping.Fields, state *fieldState, output, analyzers mapstr.M) error {
if state == nil {
// Set the defaults.
state = &fieldState{DefaultField: DefaultField}
}
for _, field := range fields {
if field.Name == "" {
continue
}
field.Path = state.Path
if field.DefaultField == nil {
field.DefaultField = &state.DefaultField
}
var (
indexMapping mapstr.M
analyzer, searchAnalyzer mapping.Analyzer
)
switch field.Type {
case "ip":
indexMapping = p.ip(&field)
case "scaled_float":
indexMapping = p.scaledFloat(&field)
case "half_float":
indexMapping = p.halfFloat(&field)
case "integer":
indexMapping = p.integer(&field)
case "text":
indexMapping, analyzer, searchAnalyzer = p.text(&field, analyzers)
case "match_only_text":
noMatchOnlyText := p.EsVersion.LessThan(minVersionMatchOnlyText)
if !p.ElasticLicensed || noMatchOnlyText {
indexMapping, analyzer, searchAnalyzer = p.text(&field, analyzers)
} else {
indexMapping, analyzer, searchAnalyzer = p.matchOnlyText(&field, analyzers)
}
case "wildcard":
noWildcards := p.EsVersion.LessThan(minVersionWildcard)
if !p.ElasticLicensed || noWildcards {
indexMapping = p.keyword(&field, analyzers)
} else {
indexMapping = p.wildcard(&field, analyzers)
}
case "", "keyword":
indexMapping = p.keyword(&field, analyzers)
case "object":
indexMapping = p.object(&field)
case "array":
indexMapping = p.array(&field)
case "alias":
indexMapping = p.alias(&field)
case "histogram":
indexMapping = p.histogram(&field)
case "nested":
mapping, err := p.nested(&field, output, analyzers)
if err != nil {
return err
}
indexMapping = mapping
case "group":
mapping, err := p.group(&field, output, analyzers)
if err != nil {
return err
}
indexMapping = mapping
default:
indexMapping = p.other(&field)
}
if *field.DefaultField {
switch field.Type {
case "", "keyword", "text", "match_only_text", "wildcard":
addToDefaultFields(&field)
}
}
if len(indexMapping) > 0 {
if field.DynamicTemplate {
// Explicit dynamic templates were introduced in
// Elasticsearch 7.13, ignore if unsupported
if !p.EsVersion.LessThan(minVersionExplicitDynamicTemplate) {
p.addDynamicTemplate(field.Name, "", "", indexMapping)
}
} else {
output.Put(mapping.GenerateKey(field.Name), indexMapping)
}
}
for _, a := range []mapping.Analyzer{
analyzer, searchAnalyzer,
} {
if a.Definition != nil {
prev, err := analyzers.Put(a.Name, a.Definition)
if err != nil {
// Should never happen.
return err
}
if prev != nil {
if !reflect.DeepEqual(prev, a.Definition) {
return fmt.Errorf("inconsistent definitions for analyzers with the name %q", a.Name)
}
}
}
}
}
return nil
}