ElasticSearch: Fallback parse total hits as int (#105615)

* Attempt int parsing

* Update total hits logic

- Do not allow the error to fail the request
- Add some comments

* Mark log as debug
This commit is contained in:
Andreas Christou
2025-05-19 18:08:38 +01:00
committed by GitHub
parent d5a8401499
commit 4a7a3f9e2a
+12 -1
View File
@@ -353,7 +353,18 @@ func processHits(dec *json.Decoder, sr *SearchResponse) error {
var total *SearchResponseHitsTotal
err := dec.Decode(&total)
if err != nil {
return err
// It's possible that the user is using an older version of Elasticsearch (or one that doesn't return what is expected)
// Attempt to parse the total value as an integer in this case
totalInt := 0
err = dec.Decode(&totalInt)
if err == nil {
total = &SearchResponseHitsTotal{
Value: totalInt,
}
} else {
// Log the error but do not fail the query
backend.Logger.Debug("failed to decode total hits", "error", err)
}
}
sr.Hits.Total = total
default: