Unable to Connect to Server from Spring boot application in es 8.12

While I am able to connect for version es 7.17 but when I am doing the same for version 8.x I am unable to connect.

I have to connect to 8.x since I want to use KNN query which it seems is only available in 8.x and later versions.

Below is my Elasticsearch Config file while I am connecting to 7.17. What needs to be fixed or added in this so that I am able to connect to 8.x version since there is a requirement of username, password and ca_cert in that

package com.similarity.match.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ElasticsearchConfig {

    @Value("${elasticsearch.host}")
    private String host;

    @Value("${elasticsearch.port}")
    private int port;

    @Value("${elasticsearch.scheme}")
    private String scheme;

    @Bean(destroyMethod = "close")
    public RestHighLevelClient restHighLevelClient() {

        return new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost(host, port, scheme)
                ).setHttpClientConfigCallback(httpAsyncClientBuilder ->
                        httpAsyncClientBuilder));
    }
}

Also how can I write a knn query using Java RestHighLevelClient. Wasn't able to find any resource for the same online.

Have you considered migrating from RHLC to ES java API? Migrating from the High Level Rest Client | Elasticsearch Java API Client [8.12] | Elastic

I tried doing the same but I getting that it is abstract and cannot be instantiated. But in the documentation it is done the way I have instantiated it.

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