Reputation: 5193
So I am trying to get my Spring Boot webservice to talk to Elasticsearch (I have another Java app that works)
The error I am getting is
DependencyException: Error creating bean with name 'searchController': Unsatisfied dependency expressed through field 'searchService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'searchService': Unsatisfied dependency expressed through field 'searchRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'searchRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder.execute()Lorg/elasticsearch/action/ListenableActionFuture; 2018-10-27 22:18:49.139 INFO 1925 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
My dependencies (Gradle) are
compile group: 'org.elasticsearch.plugin', name: 'transport-netty4-client', version: '6.4.2'
compile group: 'org.elasticsearch.client', name: 'transport', version: '6.4.2'
compile 'org.elasticsearch:elasticsearch:6.4.2'
compile('org.springframework.boot:spring-boot-starter-data-elasticsearch')
My model
@org.springframework.data.elasticsearch.annotations.Document(indexName = "burf", type = "pages")
data class Result(@Id val handle: String,
val url: String,
val title: String,
val body: String,
val meta_description: String?) {
}
Config
@Configuration
@EnableElasticsearchRepositories(basePackages = arrayOf("com.burfdevelopment.skynet.repository\n"))
@ComponentScan(basePackages = arrayOf("com.burfdevelopment.skynet.service"))
class Config {
@Value("\${elasticsearch.home:/usr/local/Cellar/elasticsearch}")
private val elasticsearchHome: String? = null
@Value("\${elasticsearch.cluster.name:skynet}")
private val clusterName: String? = null
@Bean
fun client(): Client {
val settings = Settings.builder()
.put("cluster.name", clusterName).build()
return PreBuiltTransportClient(settings).addTransportAddress(TransportAddress(InetAddress.getByName("192.168.0.100"), 9300))
}
@Bean
fun elasticsearchTemplate(): ElasticsearchOperations {
return ElasticsearchTemplate(client())
}
}
Repository
interface SearchRepository : ElasticsearchRepository<Result, String> {
fun findByTitle(name: String, pageable: Pageable): Page<Result>
}
Anyone got any idea whats wrong?
Upvotes: 1
Views: 5204
Reputation: 1140
For those who trying with 7.0, it's not yet supported on the Spring Data Elasticsearch.
Refer to the below link for elastic search versions supported.
https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#preface.versions
Alternate Approach : Use RestHighLevelClient and LowLevelClients to interact. The features of JPA will be missing.
Upvotes: 1
Reputation: 116051
The version of Spring Boot that you are using uses a version of Spring Data Elasticsearch that isn’t compatible with Elasticsearch 6.4.
To ensure that you use compatible versions, remove the version from your Elasticsearch dependencies and allow Spring Boot’s dependency management to control the version instead.
Upvotes: 5