# \[es/search\] failed: \[search\_phase\_execution\_exception\] all shards failed

**URL:** https://discuss.elastic.co/t/es-search-failed-search-phase-execution-exception-all-shards-failed/335428
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [June 7, 2023, 10:05am UTC](https://discuss.elastic.co/t/es-search-failed-search-phase-execution-exception-all-shards-failed/335428 "2023-06-07T10:05:59Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![FTOR](https://avatars.discourse-cdn.com/v4/letter/f/977dab/32.png) [@FTOR](https://discuss.elastic.co/u/FTOR)
#### Post date: [June 7, 2023, 10:05am UTC](https://discuss.elastic.co/t/es-search-failed-search-phase-execution-exception-all-shards-failed/335428/1 "2023-06-07T10:05:59Z")

</div>

Hello,

I would like to get documents from an index that contains a huge number of data ~ (1 million).  
I am using ElasticSearchClient to connect and get information from Elasticsearch. I tested the solution with a small number of data and it works well. But I got an error while testing with size(105000). Do you have an idea how to solve the problem ?

Below the implementation of the connexion, the request query and the error

 ![ElasticSearhClientMain](https://us1.discourse-cdn.com/elastic/original/3X/6/6/66e090c1d1875e9cf6e35ca445591d5d6a6fdbb7.png)

 ![SimpleSearchQuery](https://us1.discourse-cdn.com/elastic/original/3X/e/0/e0b1344a5794e31994119f837d09d3fea062ed74.png)

 ![ElasticSearchClientError](https://us1.discourse-cdn.com/elastic/original/3X/4/9/49339ef375c00283574c842ebd1cd6a61e3b4792.png)

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [June 7, 2023, 11:02pm UTC](https://discuss.elastic.co/t/es-search-failed-search-phase-execution-exception-all-shards-failed/335428/2 "2023-06-07T23:02:46Z")

</div>

Please don't post pictures of text, logs or code. They are difficult to read, impossible to search and replicate (if it's code), and some people may not be even able to see them 🙂

---

<div class="post-metadata">

### Author: ![FTOR](https://avatars.discourse-cdn.com/v4/letter/f/977dab/32.png) [@FTOR](https://discuss.elastic.co/u/FTOR)
#### Post date: [June 8, 2023, 8:40am UTC](https://discuss.elastic.co/t/es-search-failed-search-phase-execution-exception-all-shards-failed/335428/3 "2023-06-08T08:40:07Z")

</div>

Ok thank you I take note. I updated some parameter setting on the index in order to enhance the result window.  
PUT /MyIndex/\_settings  
{  
"index" : {  
"max\_result\_window" : 2100000  
}  
}

I updated the request on the code in order to get the total hits : .trackTotalHits(t-\>t.enabled(true))

SearchResponse response = client.search(s -\> s  
.index(index)  
.size(1900000)  
.trackTotalHits(t-\>t.enabled(true))  
.query(QueryBuilders.matchAll().build().\_toQuery())  
,  
MyClass.class  
);

I get more documents but it's not enough comparing to the number of documents on Elasticsearch

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [June 8, 2023, 8:45am UTC](https://discuss.elastic.co/t/es-search-failed-search-phase-execution-exception-all-shards-failed/335428/4 "2023-06-08T08:45:16Z")

</div>

What is the specification of your cluster? How much heap do you have assigned?

Increasing that limit will put a lot more load on the cluster and it is not clear it is able to handle this. Is there anything in the Elasticsearch logs?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [June 8, 2023, 9:03am UTC](https://discuss.elastic.co/t/es-search-failed-search-phase-execution-exception-all-shards-failed/335428/5 "2023-06-08T09:03:03Z")

</div>

You can use:

- the [`size` and `from` parameters](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html) to display by default up to 10000 records to your users. If you want to change this limit, you can change `index.max_result_window` setting but be aware of the consequences (ie memory).
- the [search after](https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after) feature to do deep pagination.
- the [Scroll API](https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#scroll-search-results) if you want to extract a resultset to be consumed by another tool later. (Not recommended anymore)

---

<div class="post-metadata">

### Author: ![FTOR](https://avatars.discourse-cdn.com/v4/letter/f/977dab/32.png) [@FTOR](https://discuss.elastic.co/u/FTOR)
#### Post date: [June 12, 2023, 1:30pm UTC](https://discuss.elastic.co/t/es-search-failed-search-phase-execution-exception-all-shards-failed/335428/6 "2023-06-12T13:30:41Z")

</div>

> [@dadoonet](#):
>
> - display by default up to 10000 records to your users. If you want to change this limit, you can change `index.max_result_window` setting but be aware of the consequences (ie memory).
> - the [search after](https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after) feature to do deep pagination.

Thank you for your response !  
I tried the search after with a PIT. However, I faced two issues : time performance and total number is not enough

1. Time performance: The query on dev tools takes 4s. On the other hand, it takes 10s in the java API.
2. I don't get the exact number of documents on Elasticsearch index. I think the query does not consider duplicates

---

<div class="post-metadata">

### Author: ![FTOR](https://avatars.discourse-cdn.com/v4/letter/f/977dab/32.png) [@FTOR](https://discuss.elastic.co/u/FTOR)
#### Post date: [June 12, 2023, 1:31pm UTC](https://discuss.elastic.co/t/es-search-failed-search-phase-execution-exception-all-shards-failed/335428/7 "2023-06-12T13:31:52Z")

</div>

I can not change the parameters of the cluster. They are fixed by the architects

---

<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: [July 10, 2023, 1:32pm UTC](https://discuss.elastic.co/t/es-search-failed-search-phase-execution-exception-all-shards-failed/335428/8 "2023-07-10T13:32:34Z")

</div>

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