From ec52595d8f07862c987cdd9661c24328bb1d353c Mon Sep 17 00:00:00 2001 From: Adrian Serrano Date: Thu, 24 Jun 2021 15:15:47 +0200 Subject: [PATCH] Allow fields with ip_range datatype (#26444) This updates libbeat to support fields with ip_range type. See https://www.elastic.co/guide/en/elasticsearch/reference/master/range.html --- libbeat/kibana/fields_transformer.go | 1 + libbeat/kibana/fields_transformer_test.go | 2 ++ libbeat/mapping/field.go | 2 +- libbeat/mapping/field_test.go | 5 +++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libbeat/kibana/fields_transformer.go b/libbeat/kibana/fields_transformer.go index 7009484e573..7b3db3103d9 100644 --- a/libbeat/kibana/fields_transformer.go +++ b/libbeat/kibana/fields_transformer.go @@ -293,6 +293,7 @@ var ( "geo_point": "geo_point", "date": "date", "ip": "ip", + "ip_range": "ip_range", "boolean": "boolean", } ) diff --git a/libbeat/kibana/fields_transformer_test.go b/libbeat/kibana/fields_transformer_test.go index fc7e9485536..a7c34385445 100644 --- a/libbeat/kibana/fields_transformer_test.go +++ b/libbeat/kibana/fields_transformer_test.go @@ -205,6 +205,8 @@ func TestTransformTypes(t *testing.T) { {commonField: mapping.Field{Type: "string"}, expected: nil}, {commonField: mapping.Field{Type: "date"}, expected: "date"}, {commonField: mapping.Field{Type: "geo_point"}, expected: "geo_point"}, + {commonField: mapping.Field{Type: "ip"}, expected: "ip"}, + {commonField: mapping.Field{Type: "ip_range"}, expected: "ip_range"}, {commonField: mapping.Field{Type: "invalid"}, expected: nil}, } for idx, test := range tests { diff --git a/libbeat/mapping/field.go b/libbeat/mapping/field.go index b204c9549eb..9b26284981f 100644 --- a/libbeat/mapping/field.go +++ b/libbeat/mapping/field.go @@ -153,7 +153,7 @@ func (f *Field) validateType() error { allowedFormatters = []string{"geo_point"} case "date_range": allowedFormatters = []string{"date_range"} - case "boolean", "binary", "ip", "alias", "array": + case "boolean", "binary", "ip", "alias", "array", "ip_range": // No formatters, metric types, or units allowed. case "object": if f.DynamicTemplate && (len(f.ObjectTypeParams) > 0 || f.ObjectType != "") { diff --git a/libbeat/mapping/field_test.go b/libbeat/mapping/field_test.go index 94ec4394334..52c03c6a018 100644 --- a/libbeat/mapping/field_test.go +++ b/libbeat/mapping/field_test.go @@ -364,6 +364,11 @@ func TestFieldValidate(t *testing.T) { }, err: true, }, + "allow ip_range": { + cfg: common.MapStr{"type": "ip_range"}, + err: false, + field: Field{Type: "ip_range"}, + }, } for name, test := range tests {