can i use spring data elasticsearch to connect to elastic cloud?

466 views Asked by At
@Bean
public RestHighLevelClient restClient() {

    ClientConfiguration clientConfiguration = ClientConfiguration.builder()
            .connectedTo("hostandport")
            .usingSsl()
            .withBasicAuth("username", "password")
            .build();

    return RestClients.create(clientConfiguration).rest();

}

can I use spring data elasticsearch to connect to elastic cloud and fetch the data? Do I need any config else than restclient configuration, to fetch the data from Elastic cloud?

1

There are 1 answers

0
P.J.Meisch On

Why not? Add the cluster URL(s), the authentication either as basic auth or header (https://www.elastic.co/guide/en/cloud/current/ec_connect_a_client.html) and you should be fine.