Skip to content

Commit 0ad6b94

Browse files
committed
Extract chunking from streaming_bulk
1 parent 14f5b35 commit 0ad6b94

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

elasticsearch/helpers/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ def expand_action(data):
3838

3939
return action, data.get('_source', data)
4040

41+
def _chunk_actions(actions, chunk_size):
42+
while True:
43+
yield islice(actions, chunk_size)
4144

4245
def streaming_bulk(client, actions, chunk_size=500, raise_on_error=True,
4346
expand_action_callback=expand_action, raise_on_exception=True,
@@ -100,8 +103,7 @@ def streaming_bulk(client, actions, chunk_size=500, raise_on_error=True,
100103
# if raise on error is set, we need to collect errors per chunk before raising them
101104
errors = []
102105

103-
while True:
104-
chunk = islice(actions, chunk_size)
106+
for chunk in _chunk_actions(actions, chunk_size):
105107

106108
# raise on exception means we might need to iterate on chunk twice
107109
if not raise_on_exception:

0 commit comments

Comments
 (0)