I'm using elasticsearch-java-client 7.17.4 to make my a count request to AWS Elasticsearch server like this follow code
elasticsearchClient.count(s -> s
.index("my-index")
).count();
However the follow exception was happening
Caused by: org.elasticsearch.client.ResponseException: method [POST],
host [https://my-host], URI [/my-index/_count], status line [HTTP/1.1 406 Not Acceptable]
{"error":"Content-Type header [application/vnd.elasticsearch+json; compatible-with=8] is not supported","status":406}
Looking _count api at elasticsearch RestAPI reference sound like strange because the http method is GET, but elasticsearch-java make a request with POST.
Somebody had this issue?
I forgot a important part, the response body are saying
{"error":"Content-Type header [application/vnd.elasticsearch+json; compatible-with=8]
is not supported","status":406}
Solution
RestClient restClient = RestClient
.builder(new HttpHost(url, port, scheme))
.setDefaultHeaders(new Header[]{
new BasicHeader("Content-type", "application/json")
})
.build();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With