2

I have a Spring Boot application and I want to use Elastic search 2.2.0 standalone (not the embedded server) in it, I wanna use Spring Data Elastic search, so what are the Elastic search supported versions by Spring Data and how can I configure it to connect to elasticsearch instance running in localhost:9200?

Actually, I tried adding this options to my application.properties file:

spring.data.elasticsearch.repositories.enabled=true
spring.data.elasticsearch.cluster-nodes=localhost:9200

And later, I created this configuration class:

@Configuration
public class ElasticConfig {

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

    @Bean
    public Client client() {
        TransportClient client = new TransportClient();
        TransportAddress address = new InetSocketTransportAddress(
                "localhost",9200);
        client.addTransportAddress(address);
        return client;
    }
}

I get this stacktrace:

2016-04-28 00:03:52.246 INFO 25613 --- [ restartedMain] org.elasticsearch.plugins : [Aardwolf] loaded [], sites [] 2016-04-28 00:04:01.356 INFO 25613 --- [ restartedMain] org.elasticsearch.client.transport : [Aardwolf] failed to get node info for [#transport#-1][fathi-HP-Pavilion-g6-Notebook-PC][inet[localhost/127.0.0.1:9200]], disconnecting...

org.elasticsearch.transport.ReceiveTimeoutTransportException: [][inet[localhost/127.0.0.1:9200]][cluster:monitor/nodes/info] request_id [0] timed out after [5001ms] at org.elasticsearch.transport.TransportService$TimeoutHandler.run(TransportService.java:529) ~[elasticsearch-1.5.2.jar:na] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_77] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_77] at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_77]

2016-04-28 00:04:01.512 ERROR 25613 --- [ restartedMain] .d.e.r.s.AbstractElasticsearchRepository : failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []

5
  • It's only a client. Please check your elasticsearch server status. Commented Apr 27, 2016 at 23:50
  • @Gemini Keith: elasticsearch is up and running: localhost:9200 { "name" : "Hildegarde", "cluster_name" : "elasticsearch", "version" : { "number" : "2.2.0", "build_hash" : "8ff36d139e16f8720f2947ef62c8167a888992fe", "build_timestamp" : "2016-01-27T13:32:39Z", "build_snapshot" : false, "lucene_version" : "5.4.1" }, "tagline" : "You Know, for Search" } Commented Apr 28, 2016 at 0:53
  • See this answer: stackoverflow.com/a/36858819/4604579 . Spring Data is not yet ready for ES 2.x Commented Apr 28, 2016 at 3:08
  • @Val which version of ES, i can use ? Commented Apr 28, 2016 at 10:11
  • Possible duplicate of None of the configured nodes are available issue with spring boot Commented Jul 21, 2018 at 20:46

3 Answers 3

6

I got this answer from the ES forum and it worked for me:

First, Spring Data Elasticsearch works officially with ES 1.x versions(for me it worked with 1.7.1). Second, the port used in the configuration must be 9300

I made these changes and it worked pretty perfect.

Sign up to request clarification or add additional context in comments.

1 Comment

what is the version of your spring boot?
4

As Jemli said you will need to use the port 9300.

Also make sure that your elastiscsearch client and server are using the same major version. If you are using elasticsearch 2.x you will need to update spring boot to the latest version ( > 1.4.0.RC1).

Please have a look to this post if you need more information: http://ignaciosuay.com/how-to-connect-spring-boot-to-elasticsearch-2-x-x/

1 Comment

Thanks, really helped me. Also now it is not necessary to manually configure ElasticsearchTemplate. The following Spring property will handle it nicely: spring.data.elasticsearch.cluster-nodes=localhost:9300
1

I read official document. If use Java Config,please try:

@Configuration
@EnableElasticsearchRepositories(basePackages = "org/springframework/data/elasticsearch/repositories")
static class Config {

@Bean
public ElasticsearchOperations elasticsearchTemplate() {
    return new ElasticsearchTemplate(nodeBuilder().local(true).node().client());
}
}   

If use XML, please try:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/data/elasticsearch
http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd">

<elasticsearch:transport-client id="client" cluster-nodes="localhost:9300,someip:9300" />

</beans>

You can read http://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.introduction

1 Comment

For Spring 1.4.0.RELEASE your elasticSearchTemplate method should return ElasticSearchTemplate. Original sources were mistaken on this point.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.