Skip to content

Commit fc78c99

Browse files
committed
Take skipped shards as successful in scan helper
1 parent a8c8587 commit fc78c99

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

elasticsearch/helpers/actions.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,17 +442,18 @@ def scan(
442442
yield hit
443443

444444
# check if we have any errors
445-
if resp["_shards"]["successful"] < resp["_shards"]["total"]:
445+
if (resp["_shards"]["successful"] + resp["_shards"]["skipped"]) < resp["_shards"]["total"]:
446446
logger.warning(
447-
"Scroll request has only succeeded on %d shards out of %d.",
447+
"Scroll request has only succeeded on %d (+%d skipped) shards out of %d.",
448448
resp["_shards"]["successful"],
449+
resp["_shards"]["skipped"],
449450
resp["_shards"]["total"],
450451
)
451452
if raise_on_error:
452453
raise ScanError(
453454
scroll_id,
454-
"Scroll request has only succeeded on %d shards out of %d."
455-
% (resp["_shards"]["successful"], resp["_shards"]["total"]),
455+
"Scroll request has only succeeded on %d (+%d skiped) shards out of %d."
456+
% (resp["_shards"]["successful"], resp["_shards"]["skipped"], resp["_shards"]["total"]),
456457
)
457458
resp = client.scroll(
458459
body={"scroll_id": scroll_id, "scroll": scroll}, **scroll_kwargs

test_elasticsearch/test_server/test_helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,12 @@ class TestScan(ElasticsearchTestCase):
311311
mock_scroll_responses = [
312312
{
313313
"_scroll_id": "dummy_id",
314-
"_shards": {"successful": 4, "total": 5},
314+
"_shards": {"successful": 4, "total": 5, "skipped": 0},
315315
"hits": {"hits": [{"scroll_data": 42}]},
316316
},
317317
{
318318
"_scroll_id": "dummy_id",
319-
"_shards": {"successful": 4, "total": 5},
319+
"_shards": {"successful": 4, "total": 5, "skipped": 0},
320320
"hits": {"hits": []},
321321
},
322322
]
@@ -398,7 +398,7 @@ def test_initial_search_error(self):
398398
with patch.object(self, "client") as client_mock:
399399
client_mock.search.return_value = {
400400
"_scroll_id": "dummy_id",
401-
"_shards": {"successful": 4, "total": 5},
401+
"_shards": {"successful": 4, "total": 5, "skipped": 0},
402402
"hits": {"hits": [{"search_data": 1}]},
403403
}
404404
client_mock.scroll.side_effect = self.mock_scroll_responses

0 commit comments

Comments
 (0)