Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Spring Boot with elasticsearch 5.2.1?

I am trying to connect my Spring Boot application to local elasticsearch 5.2.1 instance. When i use "org.springframework.boot:spring-boot-starter-data-elasticsearch" dependency, i face with "Received message from unsupported version: [2.0.0] minimal compatible version is: [5.0.0]". I think this is due to elasticsearch version is 2.4.4 in starter dependency. So to solve this error, i edit pom.xml properties by adding elasticsearch.version>5.2.1/elasticsearch.version> line. But this time i get "java.lang.NoSuchMethodError: org.elasticsearch.client.transport.TransportClient.builder()"

To overcome this issue, i create custom config class like below:

@Configuration
public class ElasticsearchConfiguration {

@Bean
public Client client() throws UnknownHostException {
    TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
            .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));

    return client;
}

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

This time i get apache.logging.log4j exceptions (check here) so i add necessary dependencies.

Finally i get below error and stucked there. Could anyone help me out with this?

nested exception is java.lang.NoClassDefFoundError:org/elasticsearch/action/count/CountRequestBuilder

like image 630
cek Avatar asked Feb 27 '17 20:02

cek


2 Answers

The github page of spring-data-elasticsearch shows that it currently supports elasticsearch only up to version 2.4.0.

For now you have 3 options:

  • Wait and hope
  • checkout the pull request
  • checkout the dev branch 5.0.x-prep
like image 184
Robert Schröder Avatar answered Oct 23 '22 01:10

Robert Schröder


You need to use Spring Boot 2. Check out my spring-boot-elasticsearch-5.x example.

like image 36
szxnyc Avatar answered Oct 23 '22 01:10

szxnyc