Skip to content

Commit 2bbf5a2

Browse files
ruflinandrewkroh
authored andcommitted
Add support for alias field type to fields.yml (#7645)
In elastic/elasticsearch#23714 Elasticsearch implemented the alias field type. This can be used in fields.yml as following: ``` - name: a.b type: alias path: a.c ``` `a.b` will be the alias for `a.c`.
1 parent dd5938e commit 2bbf5a2

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

libbeat/common/field.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type Field struct {
5252
DocValues *bool `config:"doc_values"`
5353
CopyTo string `config:"copy_to"`
5454
IgnoreAbove int `config:"ignore_above"`
55+
AliasPath string `config:"path"`
5556

5657
// Kibana specific
5758
Analyzed *bool `config:"analyzed"`

libbeat/template/processor.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ func (p *Processor) Process(fields common.Fields, path string, output common.Map
6262
mapping = p.object(&field)
6363
case "array":
6464
mapping = p.array(&field)
65+
case "alias":
66+
mapping = p.alias(&field)
6567
case "group":
6668
var newPath string
6769
if path == "" {
@@ -242,6 +244,13 @@ func (p *Processor) array(f *common.Field) common.MapStr {
242244
return properties
243245
}
244246

247+
func (p *Processor) alias(f *common.Field) common.MapStr {
248+
properties := getDefaultProperties(f)
249+
properties["type"] = "alias"
250+
properties["path"] = f.AliasPath
251+
return properties
252+
}
253+
245254
func (p *Processor) object(f *common.Field) common.MapStr {
246255
dynProperties := getDefaultProperties(f)
247256

libbeat/template/processor_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ func TestProcessor(t *testing.T) {
8686
output: p.array(&common.Field{Type: "array", Index: &falseVar, ObjectType: "keyword"}),
8787
expected: common.MapStr{"index": false, "type": "keyword"},
8888
},
89+
{
90+
output: p.alias(&common.Field{Type: "alias", AliasPath: "a.b"}),
91+
expected: common.MapStr{"path": "a.b", "type": "alias"},
92+
},
8993
{
9094
output: p.object(&common.Field{Type: "object", Enabled: &falseVar}),
9195
expected: common.MapStr{

libbeat/template/testdata/fields.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@
2020
- name: array_disabled
2121
type: array
2222
enabled: false
23+
24+
- name: alias
25+
type: alias
26+
path: keyword

0 commit comments

Comments
 (0)