Skip to content

Commit 233b883

Browse files
authored
Make TotalHits return 0 even if SearchResult is nil (#1473)
This will make it even more robust. Co-authored-by: qilingzhao <qilingzhao@tencent.com>
1 parent 6681d0d commit 233b883

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

search.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ type SearchResultCluster struct {
669669
// a search result. The return value might not be accurate, unless
670670
// track_total_hits parameter has set to true.
671671
func (r *SearchResult) TotalHits() int64 {
672-
if r.Hits != nil && r.Hits.TotalHits != nil {
672+
if r != nil && r.Hits != nil && r.Hits.TotalHits != nil {
673673
return r.Hits.TotalHits.Value
674674
}
675675
return 0

0 commit comments

Comments
 (0)