olivere / elastic

Deprecated: Use the official Elasticsearch client for Go at https://github.com/elastic/go-elasticsearch
https://olivere.github.io/elastic/
MIT License
7.39k stars 1.15k forks source link

()elastic.Each Swallowed the error #1664

Open huangshang0919 opened 1 year ago

huangshang0919 commented 1 year ago

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