1

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

2 Answers 2

2

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

client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
Sign up to request clarification or add additional context in comments.

1 Comment

It's partial solution :)
2

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.

1 Comment

You are correct. Gladly I did not have have problems with version of TransportClient. Still good to know that for future. But I had a lot of issues because I did not understand 9200 and 9300 default ports. Here is discussion when to use which one which helped me: elasticsearch-users.115913.n3.nabble.com/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.