2

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?

2 Answers 2

6

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.

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

4 Comments

So which lines should I remove? Do I need to downgrade my server?
You should remove the versions from the dependencies declared in your build.gradle. I don’t know what versions of the Elasticsearch client are compatible with which versions of the server. Its documentation may have some information on that.
I can't describe how useful this thread was. This should be the number one search result on Google for NoSuchMethodError elasticsearch spring boot.
@AndyWilkinson This would only work if the elasticsearch version is 6.8 or below. For those who want to make it to work for Elasticsearch version 7.0 which is not supported yet officially.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.