# Elasticsearch Java Client throws Exception when deserialize hotThreads response

**URL:** <https://discuss.elastic.co/t/elasticsearch-java-client-throws-exception-when-deserialize-hotthreads-response/365144>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [August 19, 2024, 2:06pm UTC](https://discuss.elastic.co/t/elasticsearch-java-client-throws-exception-when-deserialize-hotthreads-response/365144 "2024-08-19T14:06:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![corojoon93](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/corojoon93/32/136894_2.png) [@corojoon93](https://discuss.elastic.co/u/corojoon93)\
**Post date:** [August 19, 2024, 2:06pm UTC](https://discuss.elastic.co/t/elasticsearch-java-client-throws-exception-when-deserialize-hotthreads-response/365144/1 "2024-08-19T14:06:29Z")

</div>

I used "co.elastic.clients:elasticsearch-java:8.15.0", "org.springframework.boot:3.2.7"

And this is my Java code.

```auto
@Service
@RequiredArgsConstructor
public class NodeHealthService {

    private final ElasticsearchClient elasticsearchClient;

    public HotThreadsResponse hotThreads() throws Exception {
        return elasticsearchClient.nodes().hotThreads();
    }
}

```

This code throws TransportException when deserialize response.

co.elastic.clients.transport.TransportException: node: [https://xxxxx/](https://xxxxx/), status: 200, [es/nodes.hot\_threads] Expecting JSON data but response content-type is: text/plain; charset=UTF-8

The ElasticsearchClient configuration code is as follows:

```auto
@Configuration
public class ElasticJavaClientConfig {

    private final static int ES_CONNECTION_TIMEOUT = 5000;
    private final static int ES_SOCKET_TIMEOUT = 60000;

    @Bean
    public RestClient restClient(ElasticsearchInfoProperty elasticsearchInfoProperty) {
        final URI uri = URI.create(elasticsearchInfoProperty.url());
        final String protocol = uri.getScheme();
        final String host = uri.getHost();
        final int port = uri.getPort();
        final String username = elasticsearchInfoProperty.username();
        final String password = elasticsearchInfoProperty.password();
        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();

        credentialsProvider.setCredentials(
            AuthScope.ANY, new UsernamePasswordCredentials(username, password));

        HttpHost httpHost = new HttpHost(host, port, protocol);

        List<Header> requestHeaders = RequestOptions.DEFAULT.toBuilder()
            .addHeader(org.springframework.http.HttpHeaders.HOST, host)
            .build()
            .getHeaders();

        return RestClient.builder(httpHost)
            .setDefaultHeaders(requestHeaders.toArray(new Header[]{}))
            .setHttpClientConfigCallback(
                httpClientBuilder -> {
                    httpClientBuilder.disableAuthCaching();
                    httpClientBuilder.setKeepAliveStrategy((httpResponse, httpContext) -> 300);
                    return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
                })
            .setRequestConfigCallback(
                requestConfigBuilder -> requestConfigBuilder
                    .setConnectTimeout(ES_CONNECTION_TIMEOUT)
                    .setSocketTimeout(ES_SOCKET_TIMEOUT)).build();
    }

    @Bean
    public ElasticsearchClient elasticsearchClient(RestClient restClient) {
        ElasticsearchTransport transport = new RestClientTransport(restClient, new SimpleJsonpMapper());
        return new ElasticsearchClient(transport);
    }
}

```

What should I do to make it work properly?

---

<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:** [August 19, 2024, 2:54pm UTC](https://discuss.elastic.co/t/elasticsearch-java-client-throws-exception-when-deserialize-hotthreads-response/365144/2 "2024-08-19T14:54:02Z")

</div>

Welcome @corojoon93

Thanks for reporting. That's a bug I can reproduce. I opened:

> <https://github.com/elastic/elasticsearch-java/issues/865>
>
> \### Java API client version
> 
> 8.15.0
> 
> \### Java version
> 
> 21.0
> 
> \### Elasticsearch V…ersion
> 
> 8.15.0
> 
> \### Problem description
> 
> With the 8.15.0 client, run:
> 
> \`\`\`java
> HotThreadsResponse hotThreadsResponse = client.nodes().hotThreads();
> \`\`\`
> 
> This gives:
> 
> \`\`\`
> co.elastic.clients.transport.TransportException: node: https://localhost:63624/, status: 200, \[es/nodes.hot\_threads\] Expecting JSON data but response content-type is: text/plain; charset=UTF-8
> 
> at co.elastic.clients.transport.ElasticsearchTransportBase.checkJsonContentType(ElasticsearchTransportBase.java:471)
> at co.elastic.clients.transport.ElasticsearchTransportBase.decodeTransportResponse(ElasticsearchTransportBase.java:394)
> at co.elastic.clients.transport.ElasticsearchTransportBase.getApiResponse(ElasticsearchTransportBase.java:363)
> at co.elastic.clients.transport.ElasticsearchTransportBase.performRequest(ElasticsearchTransportBase.java:147)
> at co.elastic.clients.elasticsearch.nodes.ElasticsearchNodesClient.hotThreads(ElasticsearchNodesClient.java:199)
> at fr.pilato.test.elasticsearch.hlclient.EsClientIT.callHotThreads(EsClientIT.java:956)
> at java.base/java.lang.reflect.Method.invoke(Method.java:580)
> at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
> at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
> \`\`\`

---

<div class="post-metadata">

**Author:** ![swallez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/swallez/32/11972_2.png) [@swallez](https://discuss.elastic.co/u/swallez)\
**Post date:** [August 19, 2024, 3:44pm UTC](https://discuss.elastic.co/t/elasticsearch-java-client-throws-exception-when-deserialize-hotthreads-response/365144/3 "2024-08-19T15:44:55Z")

</div>

This API does not return JSON but a result in text format. The Java client tries to parse it as JSON, which fails.

We will update this in a future release. The workaround is to call `/_nodes/hot_threads` with the `RestClient`.

---

<div class="post-metadata">

**Author:** ![corojoon93](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/corojoon93/32/136894_2.png) [@corojoon93](https://discuss.elastic.co/u/corojoon93)\
**Post date:** [August 20, 2024, 12:56am UTC](https://discuss.elastic.co/t/elasticsearch-java-client-throws-exception-when-deserialize-hotthreads-response/365144/4 "2024-08-20T00:56:09Z")

</div>

thank you for your help!

---

<div class="post-metadata">

**Author:** ![Quentin\_Pradet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/quentin_pradet/32/94192_2.png) [@Quentin\_Pradet](https://discuss.elastic.co/u/Quentin_Pradet)\
**Post date:** [August 20, 2024, 6:15pm UTC](https://discuss.elastic.co/t/elasticsearch-java-client-throws-exception-when-deserialize-hotthreads-response/365144/5 "2024-08-20T18:15:37Z")

</div>

We fixed the specification in [Fix hot threads to always return strings by pquentin · Pull Request #2793 · elastic/elasticsearch-specification · GitHub](https://github.com/elastic/elasticsearch-specification/pull/2793), so it should be in the next version of the Java client (and all other clients).

---

<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:** [January 12, 2026, 2:13pm UTC](https://discuss.elastic.co/t/elasticsearch-java-client-throws-exception-when-deserialize-hotthreads-response/365144/6 "2026-01-12T14:13:16Z")

</div>

This should finally land in 9.3, thanks to @ltrotta😉

> <https://github.com/elastic/elasticsearch-java/pull/1135>
>
> Using the new \`response\_media\_type\` Request property introduced in the spec with… https://github.com/elastic/elasticsearch-specification/pull/5779 to correctly handle endpoints that return text/plain, including HotThreads.
> 
> Fixes https://github.com/elastic/elasticsearch-java/issues/865.
