# \[search\_phase\_execution\_exception\] without a root reason

**URL:** <https://discuss.elastic.co/t/search-phase-execution-exception-without-a-root-reason/382922>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [October 23, 2025, 1:37pm UTC](https://discuss.elastic.co/t/search-phase-execution-exception-without-a-root-reason/382922 "2025-10-23T13:37:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![al123od](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@al123od](https://discuss.elastic.co/u/al123od)\
**Post date:** [October 23, 2025, 1:37pm UTC](https://discuss.elastic.co/t/search-phase-execution-exception-without-a-root-reason/382922/1 "2025-10-23T13:37:02Z")

</div>

Hello.

I’m using Elasticsearch 9.1.3, access with java client (no security, almost all setting but cluster name are default).

If to execute query\_string query with wrong syntax like

```auto
GET test/_search

{

    "query": {

        "query_string": {

          "default_field": "description",

          "query": "\"test" /* no closing quote*/

        }

    }

} </>

```

using Kibana - I see detailed error message with description what exactly is wrong with query.

But when I run such query using Elasticsearch java client I see only top level exception in my app log, without cause (no information what is wront with query at all):

```auto
[es/search] failed: [search_phase_execution_exception] all shards failed

	at co.elastic.clients.transport.ElasticsearchTransportBase.getApiResponse(ElasticsearchTransportBase.java:372) ~[elasticsearch-java-9.1.3.jar:na]

	at co.elastic.clients.transport.ElasticsearchTransportBase.performRequest(ElasticsearchTransportBase.java:154) ~[elasticsearch-java-9.1.3.jar:na]

	at co.elastic.clients.elasticsearch.ElasticsearchClient.search(ElasticsearchClient.java:4824) ~[elasticsearch-java-9.1.3.jar:na]

```

…

Also I don’t see any message in elasticsearch logs.

Could you help with this issue, please?

---

<div class="post-metadata">

**Author:** ![RainTown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raintown/32/140206_2.png) [@RainTown](https://discuss.elastic.co/u/RainTown)\
**Post date:** [October 23, 2025, 1:39pm UTC](https://discuss.elastic.co/t/search-phase-execution-exception-without-a-root-reason/382922/2 "2025-10-23T13:39:17Z")

</div>

> [@al123od](#):
>
> `all shards failed`

Er …

Do a `GET _cat/shards` and see what it says.

---

<div class="post-metadata">

**Author:** ![al123od](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@al123od](https://discuss.elastic.co/u/al123od)\
**Post date:** [October 23, 2025, 1:41pm UTC](https://discuss.elastic.co/t/search-phase-execution-exception-without-a-root-reason/382922/3 "2025-10-23T13:41:57Z")

</div>

> [@RainTown](#):
>
> GET \_cat/shards

Everything is fine with shards, read question please. I know where is the error, I don’t understand why java exception doesn’t contain information about it. I need it for further processing.

---

<div class="post-metadata">

**Author:** ![ltrotta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ltrotta/32/124003_2.png) [@ltrotta](https://discuss.elastic.co/u/ltrotta)\
**Post date:** [October 23, 2025, 1:51pm UTC](https://discuss.elastic.co/t/search-phase-execution-exception-without-a-root-reason/382922/4 "2025-10-23T13:51:35Z")

</div>

Hello!

“all shards failed” is the high level exception, if you need more detailed information you can take the `ElasticsearchException` and dig deeper, into `response` → `error` → `reason`

---

<div class="post-metadata">

**Author:** ![RainTown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raintown/32/140206_2.png) [@RainTown](https://discuss.elastic.co/u/RainTown)\
**Post date:** [October 23, 2025, 1:52pm UTC](https://discuss.elastic.co/t/search-phase-execution-exception-without-a-root-reason/382922/5 "2025-10-23T13:52:44Z")

</div>

Sorry. Welcome to the forum.

You want to send broken queries to elasticsearch from the java client and elasticsearch to tell you precisely how they are broken when responding, irrespective of the brokenness of your query? IMHO this is unrealistic. There are options to check a query before sending to elasticsearch - try `POST index/_validate/query`

Kibana is a UI, it’s expected to check things. Like say Excel will check if you put something daft in a cell.

---

<div class="post-metadata">

**Author:** ![al123od](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@al123od](https://discuss.elastic.co/u/al123od)\
**Post date:** [October 23, 2025, 1:57pm UTC](https://discuss.elastic.co/t/search-phase-execution-exception-without-a-root-reason/382922/6 "2025-10-23T13:57:33Z")

</div>

I know this is top level exception, I can’t see reason when executing incorrect query using Elasticsearch Java client. I’ll try to explain again.

This result what I see in Kibana. You see, I have detailed description what is wrong (root\_cause, failed\_shards sections):

```auto
{

"error": {

"root_cause": [

{

"type": "query_shard_exception",

"reason": """Failed to parse query ["test]""",

"index_uuid": "ojQBM4MjSMmQ6lsa1eKgbQ",

"index": "test"

}

],

"type": "search_phase_execution_exception",

"reason": "all shards failed",

"phase": "query",

"grouped": true,

"failed_shards": [

{

"shard": 0,

"index": "test",

"node": "lb-VL2QoSgaO9iNxQSMfNw",

"reason": {

"type": "query_shard_exception",

"reason": """Failed to parse query ["test]""",

"index_uuid": "ojQBM4MjSMmQ6lsa1eKgbQ",

"index": "test",

"caused_by": {

"type": "parse_exception",

"reason": """Cannot parse '"test': Lexical error at line 1, column 6. Encountered: after prefix "\"test" (in lexical state 2)""",

"caused_by": {

"type": "token_mgr_error",

"reason": """Lexical error at line 1, column 6. Encountered: after prefix "\"test" (in lexical state 2)"""

}

}

}

}

]

},

"status": 400

}

```

In Java application I see only:

```auto
co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/search] failed: [search_phase_execution_exception] all shards failed

	at co.elastic.clients.transport.ElasticsearchTransportBase.getApiResponse(ElasticsearchTransportBase.java:372) ~[elasticsearch-java-9.1.3.jar:na]

	at co.elastic.clients.transport.ElasticsearchTransportBase.performRequest(ElasticsearchTransportBase.java:154) ~[elasticsearch-java-9.1.3.jar:na]

	at co.elastic.clients.elasticsearch.ElasticsearchClient.search(ElasticsearchClient.java:4824) ~[elasticsearch-java-9.1.3.jar:na]
....
//all other stack trace elements are my project classes or Spring-Boot related

```

---

<div class="post-metadata">

**Author:** ![al123od](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@al123od](https://discuss.elastic.co/u/al123od)\
**Post date:** [October 23, 2025, 1:59pm UTC](https://discuss.elastic.co/t/search-phase-execution-exception-without-a-root-reason/382922/7 "2025-10-23T13:59:04Z")

</div>

This is how it worked in 6.4.2. I saw Java exception with exact cause.

I’m trying to move to recent Elasticsearch version and faced this problem

---

<div class="post-metadata">

**Author:** ![ltrotta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ltrotta/32/124003_2.png) [@ltrotta](https://discuss.elastic.co/u/ltrotta)\
**Post date:** [October 23, 2025, 2:11pm UTC](https://discuss.elastic.co/t/search-phase-execution-exception-without-a-root-reason/382922/8 "2025-10-23T14:11:10Z")

</div>

Correct, this is what will be logged by default, if the exception is not handled. By catching the `ElasticsearchException` you can customize the depth of error you can log, for example:

```java
public static void main(String[] args) throws IOException {

        try (
            ElasticsearchClient client = ElasticsearchClient.of(e -> e
                .host("host")
                .apiKey("apikey"))) {

            client.search(s -> s
                .index("test")
                .query(q -> q
                    .queryString(qs -> qs
                        .query("\"test")))
            );
        } catch (ElasticsearchException e) {
            System.out.println(e.error());
        }
    }

```

will print:

```auto
ErrorCause: {"phase":"query","failed_shards":[{"shard":0,"index":"test","node":"uLsAhJL1SG6fVTHEDpVP7w","reason":{"type":"query_shard_exception","reason":"Failed to parse query [\"test]","index_uuid":"7FHHQQkBREG2GsOemvrlyw","index":"test","caused_by":{"type":"parse_exception","reason":"Cannot parse '\"test': Lexical error at line 1, column 6. Encountered: <EOF> after prefix \"\\\"test\" (in lexical state 2)","caused_by":{"type":"token_mgr_error","reason":"Lexical error at line 1, column 6. Encountered: <EOF> after prefix \"\\\"test\" (in lexical state 2)"}}}}],"grouped":true,"type":"search_phase_execution_exception","reason":"all shards failed","root_cause":[{"index_uuid":"7FHHQQkBREG2GsOemvrlyw","index":"test","type":"query_shard_exception","reason":"Failed to parse query [\"test]"}]}

```

which is the same thing you’d see in Kibana 🙂

---

<div class="post-metadata">

**Author:** ![al123od](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@al123od](https://discuss.elastic.co/u/al123od)\
**Post date:** [October 23, 2025, 2:12pm UTC](https://discuss.elastic.co/t/search-phase-execution-exception-without-a-root-reason/382922/9 "2025-10-23T14:12:41Z")

</div>

I got it, thank to **[ltrotta](https://discuss.elastic.co/u/ltrotta) ).** I just need to fetch ErrorCause like on the snippet below and read exception cause. Thank you!

```auto
} catch (Exception e) {

        	ElasticsearchException es_e = (ElasticsearchException) e;

        	ErrorCause ec = es_e.error();

```

---

<div class="post-metadata">

**Author:** ![ltrotta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ltrotta/32/124003_2.png) [@ltrotta](https://discuss.elastic.co/u/ltrotta)\
**Post date:** [October 23, 2025, 2:13pm UTC](https://discuss.elastic.co/t/search-phase-execution-exception-without-a-root-reason/382922/10 "2025-10-23T14:13:38Z")

</div>

The reason why it behaves differently from version 6.x of the old Java client is that the new Java client tries to match more closely what the server outputs, including nested exceptions. We’ve been debating overriding specifically “all shards failed” with the underlying exception, since the high level exception does not really help.

---

<div class="post-metadata">

**Author:** ![al123od](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@al123od](https://discuss.elastic.co/u/al123od)\
**Post date:** [October 23, 2025, 2:20pm UTC](https://discuss.elastic.co/t/search-phase-execution-exception-without-a-root-reason/382922/11 "2025-10-23T14:20:37Z")

</div>

In 6.4.2 it was “caused by“ series of top level exception, simple as it.

In 9.1.3 I need to examine specific fields in ElasticsearchException class. And it kinda unobvious ).
