Closed
Description
Creating a RestClientTransport
with a LLRC RequestOptions
leads every request to fail with
co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/indices.create] failed: [media_type_header_exception] Invalid media-type value on headers [Accept, Content-Type]
How to reproduce
transport = new RestClientTransport(restClient, mapper)
.withRequestOptions(new RestClientOptions.Builder(
RequestOptions.DEFAULT.toBuilder()
// add other options as needed
).build());
client = new ElasticsearchClient(transport);
Explanation
The Java API client sends a Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
header with every request, and the ES server expects to see the same value for the Accept
header. Setting custom RequestOptions
override the Java API client built-in RequestOptions
that sets this header.
Workaround
Manually set the Accept
header:
transport = new RestClientTransport(restClient, mapper)
.withRequestOptions(new RestClientOptions.Builder(
RequestOptions.DEFAULT.toBuilder()
.addHeader("Accept", "application/vnd.elasticsearch+json;compatible-with=8")
// add other options as needed
).build());
client = new ElasticsearchClient(transport);