Skip to content

Commit 084c789

Browse files
committed
Fix enabled: false validation
1 parent 35f7836 commit 084c789

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

internal/fields/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type FieldDefinition struct {
2828
MetricType string `yaml:"metric_type"`
2929
External string `yaml:"external"`
3030
Index *bool `yaml:"index"`
31+
Enabled *bool `yaml:"enabled"`
3132
DocValues *bool `yaml:"doc_values"`
3233
Normalize []string `yaml:"normalize,omitempty"`
3334
Fields FieldDefinitions `yaml:"fields,omitempty"`

internal/fields/validate.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,8 @@ func (v *Validator) validateScalarElement(key string, val any, doc common.MapStr
692692
return fmt.Errorf(`field %q is used as array of objects, expected explicit definition with type group or nested`, key)
693693
case couldBeMultifield(key, v.Schema):
694694
return fmt.Errorf(`field %q is undefined, could be a multifield`, key)
695+
case !isParentEnabled(key, v.Schema):
696+
return nil // parent mapping is disabled
695697
default:
696698
return fmt.Errorf(`field %q is undefined`, key)
697699
}
@@ -879,6 +881,17 @@ func couldBeMultifield(key string, fieldDefinitions []FieldDefinition) bool {
879881
return true
880882
}
881883

884+
// isParentEnabled returns true by default unless the parent field exists and enabled is set false
885+
// This is needed in order to correctly validate the fields that should not be mapped
886+
// because parent field mapping was disabled
887+
func isParentEnabled(key string, fieldDefinitions []FieldDefinition) bool {
888+
parent := findParentElementDefinition(key, fieldDefinitions)
889+
if parent != nil && parent.Enabled != nil && !*parent.Enabled {
890+
return false
891+
}
892+
return true
893+
}
894+
882895
func isArrayOfObjects(val any) bool {
883896
switch val := val.(type) {
884897
case []map[string]any:

0 commit comments

Comments
 (0)