Skip to content
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

()elastic.Each Swallowed the error #1664

Open
huangshang0919 opened this issue Mar 13, 2023 · 0 comments
Open

()elastic.Each Swallowed the error #1664

huangshang0919 opened this issue Mar 13, 2023 · 0 comments

Comments

@huangshang0919
Copy link

// Each is a utility function to iterate over all hits. It saves you from
// checking for nil values. Notice that Each will ignore errors in
// serializing JSON and hits with empty/nil _source will get an empty
// value
func (r *SearchResult) Each(typ reflect.Type) []interface{} {
if r.Hits == nil || r.Hits.Hits == nil || len(r.Hits.Hits) == 0 {
return nil
}
slice := make([]interface{}, 0, len(r.Hits.Hits))
for _, hit := range r.Hits.Hits {
v := reflect.New(typ).Elem()
if hit.Source == nil {
slice = append(slice, v.Interface())
continue
}
//if json.Unmarshal err,no err message,no data and Not easy to find
//if json.Unmarshal err,no err message,no data and Not easy to find
//if json.Unmarshal err,no err message,no data and Not easy to find
//if json.Unmarshal err,no err message,no data and Not easy to find
//if json.Unmarshal err,no err message,no data and Not easy to find
//if json.Unmarshal err,no err message,no data and Not easy to find
if err := json.Unmarshal(hit.Source, v.Addr().Interface()); err == nil {
slice = append(slice, v.Interface())
}
}
return slice
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant