From 2e2f8568a6b32d54003e7e5dbcc9beef3ca41854 Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Fri, 1 Apr 2022 11:27:19 +0200 Subject: [PATCH] Import patterns from ECS --- internal/fields/dependency_manager.go | 4 ++++ internal/fields/dependency_manager_test.go | 25 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/internal/fields/dependency_manager.go b/internal/fields/dependency_manager.go index 8ae592c38..f43246f97 100644 --- a/internal/fields/dependency_manager.go +++ b/internal/fields/dependency_manager.go @@ -229,6 +229,10 @@ func transformImportedField(fd FieldDefinition) common.MapStr { m["description"] = fd.Description } + if fd.Pattern != "" { + m["pattern"] = fd.Pattern + } + if fd.Index != nil { m["index"] = *fd.Index } diff --git a/internal/fields/dependency_manager_test.go b/internal/fields/dependency_manager_test.go index 10b4e6347..2b86de57d 100644 --- a/internal/fields/dependency_manager_test.go +++ b/internal/fields/dependency_manager_test.go @@ -160,6 +160,25 @@ func TestDependencyManagerInjectExternalFields(t *testing.T) { changed: true, valid: true, }, + { + title: "external with pattern", + defs: []common.MapStr{ + { + "name": "source.mac", + "external": "test", + }, + }, + result: []common.MapStr{ + { + "name": "source.mac", + "type": "keyword", + "description": "MAC address of the source.", + "pattern": "^[A-F0-9]{2}(-[A-F0-9]{2}){5,}$", + }, + }, + changed: true, + valid: true, + }, { title: "override not indexed external", defs: []common.MapStr{ @@ -228,6 +247,12 @@ func TestDependencyManagerInjectExternalFields(t *testing.T) { Index: &indexFalse, DocValues: &indexFalse, }, + { + Name: "source.mac", + Description: "MAC address of the source.", + Pattern: "^[A-F0-9]{2}(-[A-F0-9]{2}){5,}$", + Type: "keyword", + }, }} dm := &DependencyManager{schema: schema}