I am trying to set up the new Elasticsearch Java API Client.
Here is my configuration:
// Set up elasticsearch cluster hosts
String[] elasticsearchHosts = elasticsearchEndpoints.split(",");
HttpHost[] httpHosts = Arrays.stream(elasticsearchHosts)
.map(HttpHost::create).toArray(HttpHost[]::new);
// Create the low level client
final RestClientBuilder restClientbuilder = RestClient.builder(httpHosts);
// Set elasticsearch user credentials
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(username, password));
restClientbuilder.setHttpClientConfigCallback(
b -> b.setDefaultCredentialsProvider(credentialsProvider));
RestClient restClient = restClientbuilder.build();
// Create the transport with a Jackson mapper which maps classes to json
ElasticsearchTransport transport = new RestClientTransport(restClient,
new JacksonJsonpMapper());
return new ElasticsearchClient(transport);
and I have a simple search:
Query termQuery = TermQuery.of(m -> m
.field("myField")
.value("myValue"))
._toQuery();
var searchRequest =
co.elastic.clients.elasticsearch.core.SearchRequest.of(s -> s
.index("index-name")
.query(termQuery));
SearchResponse<myDTOClass>
searchResponse = elasticsearchJavaApiClient.search(searchRequest, myDTOClass.class);
It sends the request successfully but the problem is the response. Here is the error:
co.elastic.clients.transport.TransportException: node: https://aaa.xxx.com:9200/, status: 200, [es/search] Failed to decode response