Skip to content

Commit 36967e5

Browse files
committed
make scan helper deal with empty response, refs elastic#142
1 parent 9d89259 commit 36967e5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

elasticsearch/helpers/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,19 @@ def scan(client, query=None, scroll='5m', **kwargs):
173173
# initial search to
174174
resp = client.search(body=query, search_type='scan', scroll=scroll, **kwargs)
175175

176-
scroll_id = resp['_scroll_id']
176+
scroll_id = resp.get('_scroll_id')
177+
if scroll_id is None:
178+
return
177179

178180
while True:
179181
resp = client.scroll(scroll_id, scroll=scroll)
180182
if not resp['hits']['hits']:
181183
break
182184
for hit in resp['hits']['hits']:
183185
yield hit
184-
scroll_id = resp['_scroll_id']
186+
scroll_id = resp.get('_scroll_id')
187+
if scroll_id is None:
188+
break
185189

186190
def reindex(client, source_index, target_index, target_client=None, chunk_size=500, scroll='5m'):
187191
"""

0 commit comments

Comments
 (0)