olivere/elastic

()elastic.Each Swallowed the error

huangshang0919 opened this issue · 0 comments

// 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
}