more defensive merging of errors in search result status
necessary when combining after json serialization since the combinatin of omitempty tag means empty map becomes nil map
This commit is contained in:
parent
f190473c5e
commit
3627c92f08
|
@ -594,10 +594,15 @@ func MultiSearch(ctx context.Context, req *SearchRequest, indexes ...Index) (*Se
|
|||
sr.Took = searchDuration
|
||||
|
||||
// fix up errors
|
||||
for indexName, indexErr := range indexErrors {
|
||||
sr.Status.Errors[indexName] = indexErr
|
||||
sr.Status.Total++
|
||||
sr.Status.Failed++
|
||||
if len(indexErrors) > 0 {
|
||||
if sr.Status.Errors == nil {
|
||||
sr.Status.Errors = make(map[string]error)
|
||||
}
|
||||
for indexName, indexErr := range indexErrors {
|
||||
sr.Status.Errors[indexName] = indexErr
|
||||
sr.Status.Total++
|
||||
sr.Status.Failed++
|
||||
}
|
||||
}
|
||||
|
||||
return sr, nil
|
||||
|
|
|
@ -263,8 +263,13 @@ func (ss *SearchStatus) Merge(other *SearchStatus) {
|
|||
ss.Total += other.Total
|
||||
ss.Failed += other.Failed
|
||||
ss.Successful += other.Successful
|
||||
for otherIndex, otherError := range other.Errors {
|
||||
ss.Errors[otherIndex] = otherError
|
||||
if len(other.Errors) > 0 {
|
||||
if ss.Errors == nil {
|
||||
ss.Errors = make(map[string]error)
|
||||
}
|
||||
for otherIndex, otherError := range other.Errors {
|
||||
ss.Errors[otherIndex] = otherError
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue