Spring Boot with Elastic Search causing java.lang.NoSuchFieldError: IGNORE_DEPRECATIONS Spring Boot with Elastic Search causing java.lang.NoSuchFieldError: IGNORE_DEPRECATIONS elasticsearch elasticsearch

Spring Boot with Elastic Search causing java.lang.NoSuchFieldError: IGNORE_DEPRECATIONS


After some R&D, fixed the issue by adding below two dependencies:

        <dependency>            <groupId>org.elasticsearch.client</groupId>            <artifactId>elasticsearch-rest-client</artifactId>            <version>7.7.1</version>        </dependency>        <dependency>            <groupId>org.elasticsearch</groupId>            <artifactId>elasticsearch</artifactId>            <version>7.7.1</version>        </dependency>


I encountered the same problem when I was upgrading to org.elasticsearch.client:elasticsearch-rest-high-level-client:7.8.1 from 6.8.5. The reason behind the problem is updating elasticsearch-rest-high-level-client alone to the latest version conflicts with some of its dependent elastic search dependencies which were brought into classpath as transitive dependencies by spring-boot. When I check with the dependency tree, I found that the org.springframework.boot:spring-boot:2.3.1.RELEASE dependency brings org.elasticsearch.client:elasticsearch-rest-client:7.6.2, org.elasticsearch:elasticsearch:7.6.2 and the 7.6.2 conflicts with 7.8.1.

An Excerpt code snippet from the RestHighLevelClient citing IGNORE_DEPRECATIONS Java Docs.

public class RestHighLevelClient implements Closeable {    ....    ....    /**     * Ignores deprecation warnings. This is appropriate because it is only     * used to parse responses from Elasticsearch. Any deprecation warnings     * emitted there just mean that you are talking to an old version of     * Elasticsearch. There isn't anything you can do about the deprecation.     */    private static final DeprecationHandler DEPRECATION_HANDLER = DeprecationHandler.IGNORE_DEPRECATIONS;   .....   .....}

The error itself indicates us to update all related elasticsearch libraries, though I couldn't find any out-of-box elastic search BOM to resolve this version conflicts, I have done the below workaround.

dependencies{    implementation 'org.elasticsearch.client:elasticsearch-rest-client:7.8.1'    implementation 'org.elasticsearch.client:elasticsearch-rest-client:7.8.1'    implementation 'org.elasticsearch:elasticsearch:7.8.1'}//Since version 7.6.2 is selected by rule, substituting the version 7.8.1 as belowconfigurations.all {    resolutionStrategy {        dependencySubstitution {            substitute module('org.elasticsearch.client:elasticsearch-rest-high-level-client') with module('org.elasticsearch.client:elasticsearch-rest-high-level-client:7.8.1')            substitute module('org.elasticsearch.client:elasticsearch-rest-client') with module('org.elasticsearch.client:elasticsearch-rest-client:7.8.1')            substitute module('org.elasticsearch:elasticsearch') with module('org.elasticsearch:elasticsearch:7.8.1')                  }  }}


You are not correctly initializing your elasticsearch client, can you try with below code:

Please note that I am using the version which accepts the host, port and http scheme and it works fine for me and is the standard for creating the client.

@Configuration@Primarypublic class ElasticsearchConfig {    /**     * Creates a Elasticsearch client from config     *     * @return Elasticsearch client     */    @Bean(destroyMethod = "close")    public RestHighLevelClient client() {        RestHighLevelClient client = new RestHighLevelClient(            RestClient.builder(new HttpHost("localhost", 9500, "http")));        return client;    }}

And use below config

elasticsearch.host=localhostelasticsearch.port=9500