I'm following the tutorial from elastic search java api client here: https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/connecting.html
My code is as following.
// Create the low-level client
RestClient restClient = RestClient.builder(
new HttpHost("localhost", 9200)).build();
// Create the transport with a Jackson mapper
ElasticsearchTransport transport = new RestClientTransport(
restClient, new JacksonJsonpMapper());
// And create the API client
ElasticsearchClient client = new ElasticsearchClient(transport);
try {
SearchResponse<Object> search = client.search(s -> s
.index("*:*"),
Object.class);
} catch (IOException e) {
System.out.println(e.getMessage());
}
This code is throwing out the following exception:
co.elastic.clients.transport.TransportException: [es/search] Missing [X-Elastic-Product] header. Please check that you are connecting to an Elasticsearch instance, and that any networking filters are preserving that header.
I've tried manually putting this header via the setDefaultHeaders
method like this:
RestClientBuilder builder = RestClient.builder(
new HttpHost("localhost", 9200, "http"));
Header[] defaultHeaders = new Header[]{new BasicHeader("X-Elastic-Product", "Elasticsearch")};
builder.setDefaultHeaders(defaultHeaders);
RestClient restClient = builder.build();
But the error is the same.
I've tried both version 7.16 and 8.0.0, same result.