-
Notifications
You must be signed in to change notification settings - Fork 609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
types.Property is not correctly unmarshaled when child mapping elements have no "type" field. #696
Comments
Wher do I need to look into? There should be code generator which has generated these code as it states so. But I've not yet found it. |
I am also finding issues using the simulate template API, it seems to incorrectly unmarshal nested properties. I think the problem is in go-elasticsearch/typedapi/types/typemapping.go Lines 442 to 445 in 87bb1b4
Replacing this part with the following code seems to fix the issue:
@Anaethelion do you know where we can change the generator to fix this? Thanks! |
I thought a correct fix would be ty, ok := kind["type"]
if !ok {
ty = "object"
}
switch ty {
case "binary":
oo := NewBinaryProperty()
if err := localDec.Decode(&oo); err != nil {
return err
}
s.Properties[key] = oo
case "boolean":
oo := NewBooleanProperty()
if err := localDec.Decode(&oo); err != nil {
return err
}
s.Properties[key] = oo
// ... rest of cases ...
default:
return fmt.Errorf("unknown type %s", ty)
} |
Since the specification has the I've already commited a fallback in the PR, I'm working on a follow-up to handle both the default case and unknown members. |
I'm glad to know that I didn't know that part. Would it be like this? ty, ok := kind["type"]
if !ok {
ty = "object"
}
switch ty {
case "binary":
oo := NewBinaryProperty()
if err := localDec.Decode(&oo); err != nil {
return err
}
s.Properties[key] = oo
case "boolean":
oo := NewBooleanProperty()
if err := localDec.Decode(&oo); err != nil {
return err
}
s.Properties[key] = oo
// ... rest of cases ...
default:
// plugins might be able to handle this.
var oo any
if err := localDec.Decode(&oo); err != nil {
return err
}
s.Properties[key] = oo
} Thank you for the fix. I'll wait for next release. |
Thanks @Anaethelion! |
* TypedClient: remove ndjson helper, not yet ready * TypedClient: fix #696 * TypedClient: add handling for default type in unions (Property & Analyzer)
Released as part of |
Types which contain
types.Property
are not correctly unmarshaled when input mapping denifitions have no "type" field.For example this part, types.TypeMapping is not handling absence of "type" field.
go-elasticsearch/typedapi/types/typemapping.go
Lines 165 to 446 in afe8f26
https://www.elastic.co/guide/en/elasticsearch/reference/current/object.html
As stated in the official document, this is not correct behavior.
The text was updated successfully, but these errors were encountered: