How to configure Spring Boot with elasticsearch 5.2.1?

浪子不回头ぞ 提交于 2019-12-10 13:00:56

问题


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


回答1:


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



回答2:


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




回答3:


You can use elasticsearch java api to create transport client instead of using spring-data-elasticsearch.




回答4:


I tried the same and getting that error too for CountRequestBuilder, reason is that CountRequestBuilder class is deprecated and removed now from 5.x elastic search versions, that class is replaced by SearchRequestBuilder but unfortunately spring-data-elasticsearch don't provide this even in the latest release of its jar and that CountRequestBuilder is used in ElasticSearchTemplate.

I am also looking out for some solution. I will post if able to resolve.



来源:https://stackoverflow.com/questions/42495090/how-to-configure-spring-boot-with-elasticsearch-5-2-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!