0
0
Fork 0

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:
Marty Schoch 2016-03-10 16:02:53 -05:00
parent f190473c5e
commit 3627c92f08
2 changed files with 16 additions and 6 deletions

View File

@ -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

View File

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