diff --git a/typedapi/types/datedecayfunction.go b/typedapi/types/datedecayfunction.go index a5e4a5cc9e..652f3d5165 100644 --- a/typedapi/types/datedecayfunction.go +++ b/typedapi/types/datedecayfunction.go @@ -21,8 +21,11 @@ package types import ( + "bytes" "encoding/json" + "errors" "fmt" + "io" "github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/multivaluemode" ) @@ -37,6 +40,42 @@ type DateDecayFunction struct { MultiValueMode *multivaluemode.MultiValueMode `json:"multi_value_mode,omitempty"` } +func (s *DateDecayFunction) UnmarshalJSON(data []byte) error { + + dec := json.NewDecoder(bytes.NewReader(data)) + + for { + t, err := dec.Token() + if err != nil { + if errors.Is(err, io.EOF) { + break + } + return err + } + + switch t { + + case "multi_value_mode": + if err := dec.Decode(&s.MultiValueMode); err != nil { + return fmt.Errorf("%s | %w", "MultiValueMode", err) + } + default: + if key, ok := t.(string); ok { + if s.DecayFunctionBaseDateMathDuration == nil { + s.DecayFunctionBaseDateMathDuration = make(map[string]DecayPlacementDateMathDuration) + } + raw := new(DecayPlacementDateMathDuration) + if err := dec.Decode(&raw); err != nil { + return fmt.Errorf("%s | %w", "DecayPlacementDateMathDuration", err) + } + s.DecayFunctionBaseDateMathDuration[key] = *raw + } + + } + } + return nil +} + // MarhsalJSON overrides marshalling for types with additional properties func (s DateDecayFunction) MarshalJSON() ([]byte, error) { type opt DateDecayFunction