Reputation: 197
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
Upvotes: 7
Views: 7884
Reputation: 2585
You need to use Spring Boot 2. Check out my spring-boot-elasticsearch-5.x example.
Upvotes: 3
Reputation: 315
You can use elasticsearch java api to create transport client instead of using spring-data-elasticsearch.
Upvotes: 2
Reputation: 188
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:
Upvotes: 4
Reputation: 11
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.
Upvotes: 1