Skip to content

Commit 9e4d0dd

Browse files
committed
Move the bulk body construction into _chunk_actions
1 parent a177375 commit 9e4d0dd

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

elasticsearch/helpers/__init__.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@ def expand_action(data):
4040

4141
def _chunk_actions(actions, chunk_size):
4242
while True:
43-
yield islice(actions, chunk_size)
43+
bulk_actions = []
44+
for action, data in islice(actions, chunk_size):
45+
bulk_actions.append(action)
46+
if data is not None:
47+
bulk_actions.append(data)
48+
49+
if not bulk_actions:
50+
return
51+
52+
yield bulk_actions
4453

4554
def streaming_bulk(client, actions, chunk_size=500, raise_on_error=True,
4655
expand_action_callback=expand_action, raise_on_exception=True,
@@ -103,16 +112,8 @@ def streaming_bulk(client, actions, chunk_size=500, raise_on_error=True,
103112
# if raise on error is set, we need to collect errors per chunk before raising them
104113
errors = []
105114

106-
for chunk in _chunk_actions(actions, chunk_size):
115+
for bulk_actions in _chunk_actions(actions, chunk_size):
107116

108-
bulk_actions = []
109-
for action, data in chunk:
110-
bulk_actions.append(action)
111-
if data is not None:
112-
bulk_actions.append(data)
113-
114-
if not bulk_actions:
115-
return
116117

117118
try:
118119
# send the actual request

0 commit comments

Comments
 (0)