# Elasticsearch-dsl Python Library Using Scan

**URL:** <https://discuss.elastic.co/t/elasticsearch-dsl-python-library-using-scan/216743>\
**Category:** Elasticsearch\
**Created:** [January 28, 2020, 1:46am UTC](https://discuss.elastic.co/t/elasticsearch-dsl-python-library-using-scan/216743 "2020-01-28T01:46:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ellje](https://avatars.discourse-cdn.com/v4/letter/e/7993a0/32.png) [@ellje](https://discuss.elastic.co/u/ellje)\
**Post date:** [January 28, 2020, 1:46am UTC](https://discuss.elastic.co/t/elasticsearch-dsl-python-library-using-scan/216743/1 "2020-01-28T01:46:28Z")

</div>

My code here essentially is

```auto
for hit in search.scan():
    do something

```

I believe it will use pagination/scrolling on this, and it seems that after a while, it will have this error message:

> **17:23:34** for hit in search.scan():  
> **17:23:34** File "/usr/lib/python2.7/site-packages/elasticsearch\_dsl/search.py", line 719, in scan **17:23:34** \*\*self.\_params  
> **17:23:34** File "/usr/lib/python2.7/site-packages/elasticsearch/helpers/actions.py", line 469, in scan  
> **17:23:34** body={"scroll\_id": scroll\_id, "scroll": scroll}, \*\*scroll\_kwargs  
> **17:23:34** File "/usr/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 84, in \_wrapped  
> **17:23:34** return func(\*args, params=params, \*\*kwargs)  
> **17:23:34** File "/usr/lib/python2.7/site-packages/elasticsearch/client/ **init**.py", line 1395, in scroll  
> **17:23:34**"GET", "/\_search/scroll", params=params, body=body  
> **17:23:34** File "/usr/lib/python2.7/site-packages/elasticsearch/transport.py", line 358, in perform\_request  
> **17:23:34** timeout=timeout,  
> **17:23:34** File "/usr/lib/python2.7/site-packages/elasticsearch/connection/http\_urllib3.py", line 261, in perform\_request  
> **17:23:34** self.\_raise\_error(response.status, raw\_data)  
> **17:23:34** File "/usr/lib/python2.7/site-packages/elasticsearch/connection/base.py", line 182, in \_raise\_error  
> **17:23:34** status\_code, error\_message, additional\_info  
> **17:23:34** elasticsearch.exceptions.NotFoundError: NotFoundError(404, u'search\_phase\_execution\_exception', u'No search context found for id [19079999]')

I've read that this is because it took too long for the scroll to respond, and that I would have to calibrate it according to how my cluster is set up (currently, a single cluster with a single node. Unfortunately, cannot upgrade it yet).

How do I calibrate it? What do I look for to ensure good performance? Any suggestion is appreciated.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 25, 2020, 1:46am UTC](https://discuss.elastic.co/t/elasticsearch-dsl-python-library-using-scan/216743/2 "2020-02-25T01:46:29Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
