Cannot read data from Elastic 6.0: "error":"Content-Type header [text/plain] is not supported","status":406

Hi experts,

I create a client in java and want to get the query results from index but got the 406 error:
"Content-Type header [text/plain] is not supported","status":406.

Java platform: 1.6
ES version: 6.0

Below is the code snippet:

  Client clientInstance = Client.create();
  clientInstance.addFilter(new HTTPBasicAuthFilter("", "")); // No Auth in sample RI

  WebResource webResource =
      clientInstance.resource("http://hostname:9200/indexname/_search"); 
  ClientResponse response =
      webResource.entity(aggDsl).accept("application/json").get(ClientResponse.class);

  String resultEntity = response.getEntity(String.class);

I use the DSL in kibana and can get the correct query results. But it did not get the correct response in java and throw 406 error.

How can I fix this issue? Thanks veru much!

You need to provide the Content-Type.

1 Like

I didn't see it was cross-posted, but I answered here

Yes, it solves this issue and thanks.

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