Skip to content

Commit a9bc375

Browse files
authored
Accept null as array in fields in test documents (#1501)
1 parent cb8d66c commit a9bc375

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

internal/fields/validate.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,9 @@ func (v *Validator) parseSingleElementValue(key string, definition FieldDefiniti
804804
break
805805
}
806806
return forEachElementValue(key, definition, val, doc, v.parseSingleElementValue)
807+
case nil:
808+
// The document contains a null, let's consider this like an empty array.
809+
return nil
807810
default:
808811
return fmt.Errorf("field %q is a group of fields, it cannot store values", key)
809812
}

internal/fields/validate_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,21 @@ func Test_parseElementValue(t *testing.T) {
736736
}
737737
},
738738
},
739+
{
740+
key: "null_array",
741+
value: nil,
742+
definition: FieldDefinition{
743+
Name: "null_array",
744+
Type: "group",
745+
Fields: []FieldDefinition{
746+
{
747+
Name: "id",
748+
Type: "keyword",
749+
},
750+
},
751+
},
752+
specVersion: *semver3_0_1,
753+
},
739754
} {
740755

741756
t.Run(test.key, func(t *testing.T) {

0 commit comments

Comments
 (0)