# Elasticsearch search\_phase\_execution\_exception in Python

**URL:** https://discuss.elastic.co/t/elasticsearch-search-phase-execution-exception-in-python/280763
**Category:** Elasticsearch
**Created:** [August 9, 2021, 6:35am UTC](https://discuss.elastic.co/t/elasticsearch-search-phase-execution-exception-in-python/280763 "2021-08-09T06:35:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![rknd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rknd/32/103882_2.png) [@rknd](https://discuss.elastic.co/u/rknd)
#### Post date: [August 9, 2021, 6:35am UTC](https://discuss.elastic.co/t/elasticsearch-search-phase-execution-exception-in-python/280763/1 "2021-08-09T06:35:42Z")

</div>

I fetch all my Elasticsearch documents via using scroll api with below code in Python.

```auto
size = 100
data = es.search(
            index=index,
            scroll='25m',
            size=size,
            body=body
        )
max_val = data['hits']['total']['value']

sid = data['_scroll_id']
scroll_size = len(data['hits']['hits'])
while scroll_size > 0:
    .........
    data = es.scroll(scroll_id=sid, scroll='25m')
    sid = data['_scroll_id']
    scroll_size = len(data['hits']['hits'])

```

In some index I have less then 100 documents and some of them I have more than 30000 documents thats why I use scroll api.

I've written this code via this [tutorial](https://kb.objectrocket.com/elasticsearch/how-to-use-python-to-make-scroll-queries-to-get-all-documents-in-an-elasticsearch-index-752)

The code works, but after some time, I get the below error.

```auto
NotFoundError(404, 'search_phase_execution_exception', 'No search context found for id

```

I tried to solve this error with changing scroll. The scroll was 5m and then I set 25m but still get same error. How can i solve this?

Thanks for answering

---

<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: [September 6, 2021, 6:35am UTC](https://discuss.elastic.co/t/elasticsearch-search-phase-execution-exception-in-python/280763/2 "2021-09-06T06:35:46Z")

</div>

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