Propagate request_timeout to scroll calls

Fixes #434
This commit is contained in:
Honza Král
2016-08-29 15:46:46 +02:00
parent ef390c2888
commit d4efb81b06
+5 -3
View File
@@ -237,7 +237,7 @@ def parallel_bulk(client, actions, thread_count=4, chunk_size=500,
pool.join() pool.join()
def scan(client, query=None, scroll='5m', raise_on_error=True, def scan(client, query=None, scroll='5m', raise_on_error=True,
preserve_order=False, size=1000, **kwargs): preserve_order=False, size=1000, request_timeout=None, **kwargs):
""" """
Simple abstraction on top of the Simple abstraction on top of the
:meth:`~elasticsearch.Elasticsearch.scroll` api - a simple iterator that :meth:`~elasticsearch.Elasticsearch.scroll` api - a simple iterator that
@@ -260,6 +260,7 @@ def scan(client, query=None, scroll='5m', raise_on_error=True,
can be an extremely expensive operation and can easily lead to can be an extremely expensive operation and can easily lead to
unpredictable results, use with caution. unpredictable results, use with caution.
:arg size: size (per shard) of the batch send at each iteration. :arg size: size (per shard) of the batch send at each iteration.
:arg request_timeout: explicit timeout for each call to ``scan``
Any additional keyword arguments will be passed to the initial Any additional keyword arguments will be passed to the initial
:meth:`~elasticsearch.Elasticsearch.search` call:: :meth:`~elasticsearch.Elasticsearch.search` call::
@@ -275,7 +276,8 @@ def scan(client, query=None, scroll='5m', raise_on_error=True,
body = query.copy() if query else {} body = query.copy() if query else {}
body["sort"] = "_doc" body["sort"] = "_doc"
# initial search # initial search
resp = client.search(body=query, scroll=scroll, size=size, **kwargs) resp = client.search(body=query, scroll=scroll, size=size,
request_timeout=request_timeout, **kwargs)
scroll_id = resp.get('_scroll_id') scroll_id = resp.get('_scroll_id')
if scroll_id is None: if scroll_id is None:
@@ -288,7 +290,7 @@ def scan(client, query=None, scroll='5m', raise_on_error=True,
if first_run: if first_run:
first_run = False first_run = False
else: else:
resp = client.scroll(scroll_id, scroll=scroll) resp = client.scroll(scroll_id, scroll=scroll, request_timeout=request_timeout)
for hit in resp['hits']['hits']: for hit in resp['hits']['hits']:
yield hit yield hit