Spring boot data Elastic Cloud integration

Hi,

We are using spring-boot 2.1.4 with spring-data-elasticsearch-starter
This worked perfectly to our self-installed ES cluster running without x-pack. ES version 6.5.2

Then we signed up for Elastic Cloud and got a trial running.
Since its using X-pack we have added an Xpack transportclient, but its just not working.
We have now tried everything we can think of and cannot find any information about this by googling.
Does anyone have any help to offer? It shouldnt be this difficult to connect right?

Here is some sample code and errors:
pom: spring boot version 2.1.4.RELEASE

org.springframework.boot
spring-boot-starter-data-elasticsearch


org.elasticsearch.client
transport


    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>x-pack-transport</artifactId>
        <version>6.2.0</version>
    </dependency>

Extra config:

@Configuration
public class SearchConfig {
@Value("${elastic.username}")
private String elasticUsername;
@Value("${elastic.password}")
private String elasticPassword;
@Value("${elastic.hostName}")
private String elasticHostname;
@Value("${elastic.clusterName}")
private String elasticClusterName;
@Value("${elastic.port}")
private int elasticPort;

@Bean
public TransportClient elasticsearchClient() {

    String credentials = elasticUsername + ":" + elasticPassword;

    Settings settings = Settings.builder()
            .put("client.transport.nodes_sampler_interval", "5s")
            .put("client.transport.sniff", false)
            .put("transport.tcp.compress", true)
            .put("cluster.name", elasticClusterName)
            .put("xpack.security.transport.ssl.enabled", true)
            .put("request.headers.X-Found-Cluster", elasticClusterName)
            .put("xpack.security.user", credentials)
            .build();

    return new PreBuiltXPackTransportClient(settings)
            .addTransportAddress(new TransportAddress(new InetSocketAddress(elasticHostname, elasticPort)));
}
}

And the corresponding errror:

Caused by: java.lang.IllegalArgumentException: NamedWriteable [org.elasticsearch.cluster.NamedDiff][persistent_tasks] is already registered for [org.elasticsearch.cluster.ClusterModule$$Lambda$1227/848564270], cannot register [org.elasticsearch.xpack.core.XPackClientPlugin$$Lambda$1234/1686279280]
at org.elasticsearch.common.io.stream.NamedWriteableRegistry.<init>(NamedWriteableRegistry.java:91)
at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:162)
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:283)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:128)
at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.<init>(PreBuiltXPackTransportClient.java:59)
at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.<init>(PreBuiltXPackTransportClient.java:54)
at org.elasticsearch.xpack.client.PreBuiltXPackTransportClient.<init>(PreBuiltXPackTransportClient.java:50)
at no.dahlsdata.elasticsearch.SearchConfig.elasticsearchClient(SearchConfig.java:45)

I found a solution-ish, at the least I progressed to the next error. I updated to the latest version for transport ( 6.7.2 - for this given time) : https://mvnrepository.com/artifact/org.elasticsearch.client/transport

Here is a link to a helpful post: Java transport client do not work after upgrade to 6.5.3

-- Previous Comments --

I have come across this same issue this morning. Where you able to find a solution?

I'm wandering if Spring Data is automatically configuring the NamedWriteable bean. I tried the following with no success:

@SpringBootApplication(exclude = {ElasticsearchAutoConfiguration.class, ElasticsearchDataAutoConfiguration.class})

spring:
  autoconfigure:
    exclude:
      - org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration
      - org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration

Hello!

In my case it was actually just due to wrong port. Took me some time to figure out. I dont remember exactly the ports and why it was wrong but there was something with the ports.

Really! That may be my issue. Are you using ESCloud? What is the other standard port than 9243?

Try 9343

Works for me. :wink:

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