# How to extract error root cause reason using Java RestHighLevelClient?

**URL:** <https://discuss.elastic.co/t/how-to-extract-error-root-cause-reason-using-java-resthighlevelclient/284801>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [September 22, 2021, 5:15am UTC](https://discuss.elastic.co/t/how-to-extract-error-root-cause-reason-using-java-resthighlevelclient/284801 "2021-09-22T05:15:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nishikant\_Tayade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nishikant_tayade/32/84159_2.png) [@Nishikant\_Tayade](https://discuss.elastic.co/u/Nishikant_Tayade)\
**Post date:** [September 22, 2021, 5:15am UTC](https://discuss.elastic.co/t/how-to-extract-error-root-cause-reason-using-java-resthighlevelclient/284801/1 "2021-09-22T05:15:07Z")

</div>

Hi,

I am trying to perform a wildcard query on date type, which is not allowed by ES, so I see an exception being thrown from ES as below:

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "query_shard_exception",
        "reason": "Can only use wildcard queries on keyword, text and wildcard fields - not on [OrderDate] which is of type [date]",
        "index_uuid": "cypJ5a9eTlmGhQkJy_BJAQ",
        "index": "order_202109"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "order_202109",
        "node": "TkkTI0EhTsC2_5QxtzN0Rw",
        "reason": {
          "type": "query_shard_exception",
          "reason": "Can only use wildcard queries on keyword, text and wildcard fields - not on [OrderDate] which is of type [date]",
          "index_uuid": "cypJ5a9eTlmGhQkJy_BJAQ",
          "index": "order_202109"
        }
      }
    ]
  },
  "status": 400
}

```

But when I get the rootCause from ElasticsearchException

```auto
Throwable cause = ElasticsearchException.getRootCause();
cause.getMessage();

```

It only gives me

```auto
 "type": "search_phase_execution_exception",
 "reason": "all shards failed",

```

Is there any utility method to extract the actual error root cause, which is

```auto
 "type": "query_shard_exception",
  "reason": "Can only use wildcard queries on keyword, text and wildcard fields - not on [OrderDate] which is of type [date]"

```

Thank you:)

---

<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:** [October 20, 2021, 5:15am UTC](https://discuss.elastic.co/t/how-to-extract-error-root-cause-reason-using-java-resthighlevelclient/284801/2 "2021-10-20T05:15:36Z")

</div>

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