NoNodeAvailableException, cannot connect SpringBoot 2.0 and Elasticsearch5.5.0

Hello,

I know it was discussed several times however after reading all threads I am still not able connect SpringBoot 2.0 application to ElasticSearch 5.5.0 while using TransportClient (as Java High-Level REST Client was released in ver 5.6.0 i can't use it).

Here's my application so far:

pom.xml

org.springframework.boot
spring-boot-starter-parent
2.0.1.BUILD-SNAPSHOT

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

config class
@Configuration
@EnableElasticsearchRepositories(basePackages = "com.example.demo")
public class EsConfig {

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

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

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

    @Bean
    public Client client() throws Exception {

        Settings esSettings = Settings.builder()
                .put("cluster.name", EsClusterName)
                .build();

        TransportClient client = new PreBuiltTransportClient(esSettings)
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(EsHost), Integer.valueOf(EsPort)));
        return client;
    }

    @Bean
    public ElasticsearchOperations elasticsearchTemplate() throws Exception {
        return new ElasticsearchTemplate(client());
    }
}

application.properties
elasticsearch.clustername = elasticsearch
elasticsearch.host = localhost
elasticsearch.port = 9300

As i run the application I get an error:

failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{ru3fMzoqTQygBpT5C6KXXw}{localhost}{127.0.0.1:9300}]

My elasticsearch is running in docker container

run -p 9200:9200 -p 9300:9300 --name elasticsearch -d --network mynetwork elasticsearch:5.5.0

TransportClient is set to listen on Port 9300
SpringBoot 2.0 should be compatible with Elastic 5.X
Does anyone know what could I change in order to make it work ?
Thanks

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