Jakub
Jakub

Reputation: 2141

Spring Data ElasticSearch - cannot connect to node

I'm trygin to configure ElasticSearch repositories in Spring MVC application. I'm using Spring Data ElasticSearch version: 2.0.7 and ElasticSearch Server 2.4.4.

I'm sure that ElasticNode work, here is sample output

$ curl -X GET http://127.0.0.1:9200/
{
  "name" : "Tattoo",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "dX0lPfNnSA6vxGqhzVEuSg",
  "version" : {
    "number" : "2.4.4",
    "build_hash" : "fcbb46dfd45562a9cf00c604b30849a6dec6b017",
    "build_timestamp" : "2017-01-03T11:33:16Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.2"
  },
  "tagline" : "You Know, for Search"
}

Here is my test configuration

@Configuration
@EnableElasticsearchRepositories(basePackages = "com.somepackage.repo.elastic")
public class ElasticSearchConfig {

@Bean
public ElasticsearchTemplate elasticsearchTemplate() throws UnknownHostException {
    return new ElasticsearchTemplate(nodeClient());
}

@Bean
public TransportClient nodeClient() throws UnknownHostException {

    Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();
    TransportClient client = TransportClient.builder()
            .settings(settings)
            .build();
    client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9200));
    return client;

}
}

I'm getting errors that application cannot connect to Elastic node, stacktrace

2017-02-17 23:34:53 INFO  transport:383 - [Impulse] failed to get node info for {#transport#-1}{127.0.0.1}{localhost/127.0.0.1:9200}, disconnecting...
ReceiveTimeoutTransportException[[][localhost/127.0.0.1:9200][cluster:monitor/nodes/liveness] request_id [1] timed out after [5002ms]]
    at org.elasticsearch.transport.TransportService$TimeoutHandler.run(TransportService.java:645)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

I tried to change versions of elastic search nodes from 1.7.1, 2.4.4 and 5.2.1. Nothing works. Spring MVC 4.3.6.RELEASE with Java 8

Upvotes: 1

Views: 2093

Answers (2)

Jakub
Jakub

Reputation: 2141

In short: ElasticSearch node and TransportClient should have the same version.

Spring Data ElasticSearch provides TransportClient in version 2.2.0. I was using ElasticSearch node in version 2.4.4. I downgraded ES node to 2.2.0 and change port from 9200 to 9300 in configuration.

Upvotes: 2

Mario Trucco
Mario Trucco

Reputation: 2011

The Transport client talks to elasticsearch over port 9300. So try

client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));

Upvotes: 2

Related Questions