Skip to content

Commit

Permalink
Add support for alias field type to fields.yml
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
ruflin committed Jul 23, 2018
1 parent ff45ef8 commit 79bb176
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions libbeat/common/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Field struct {
DocValues *bool `config:"doc_values"`
CopyTo string `config:"copy_to"`
IgnoreAbove int `config:"ignore_above"`
AliasPath string `config:"path"`

// Kibana specific
Analyzed *bool `config:"analyzed"`
Expand Down
9 changes: 9 additions & 0 deletions libbeat/template/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func (p *Processor) Process(fields common.Fields, path string, output common.Map
mapping = p.object(&field)
case "array":
mapping = p.array(&field)
case "alias":
mapping = p.alias(&field)
case "group":
var newPath string
if path == "" {
Expand Down Expand Up @@ -242,6 +244,13 @@ func (p *Processor) array(f *common.Field) common.MapStr {
return properties
}

func (p *Processor) alias(f *common.Field) common.MapStr {
properties := getDefaultProperties(f)
properties["type"] = "alias"
properties["path"] = f.AliasPath
return properties
}

func (p *Processor) object(f *common.Field) common.MapStr {
dynProperties := getDefaultProperties(f)

Expand Down
4 changes: 4 additions & 0 deletions libbeat/template/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func TestProcessor(t *testing.T) {
output: p.array(&common.Field{Type: "array", Index: &falseVar, ObjectType: "keyword"}),
expected: common.MapStr{"index": false, "type": "keyword"},
},
{
output: p.alias(&common.Field{Type: "alias", AliasPath: "a.b"}),
expected: common.MapStr{"path": "a.b", "type": "alias"},
},
{
output: p.object(&common.Field{Type: "object", Enabled: &falseVar}),
expected: common.MapStr{
Expand Down
4 changes: 4 additions & 0 deletions libbeat/template/testdata/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
- name: array_disabled
type: array
enabled: false

- name: alias
type: alias
path: keyword

0 comments on commit 79bb176

Please sign in to comment.