diff --git a/elasticsearch/helpers/actions.py b/elasticsearch/helpers/actions.py index 87fcc305d..3042de044 100644 --- a/elasticsearch/helpers/actions.py +++ b/elasticsearch/helpers/actions.py @@ -524,14 +524,34 @@ def scan( resp["_shards"]["skipped"], resp["_shards"]["total"], ) + + resp_failures = resp["_shards"].get("failures") + failures = [] + if resp_failures is not None: + for i in range(5): + if i < len(resp_failures): + failure = "Failure type[%s] received with reason: %s" % ( + resp_failures[i]["reason"]["type"], + resp_failures[i]["reason"]["reason"], + ) + failures.append(failure) + logger.warning(failure) + + if len(resp_failures) > 5: + omitted_failures = len(resp_failures) - 5 + failures.append( + "...and %d more omitted failures" % omitted_failures + ) if raise_on_error: raise ScanError( scroll_id, - "Scroll request has only succeeded on %d (+%d skiped) shards out of %d." + "Scroll request has only succeeded on %d (+%d skipped) shards out of %d.\n" + "%s" % ( resp["_shards"]["successful"], resp["_shards"]["skipped"], resp["_shards"]["total"], + "\n".join(failures), ), ) resp = client.scroll(