NoSuchMethodError: org.elasticsearch.action.search.SearchResponse.fromXContent

Hello, I'm trying to use the high level API like this:

    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials("user", "pass"));

    RestClientBuilder builder = RestClient.builder(
            new HttpHost("host1", 9200, "http"),
            new HttpHost("host2", 9200, "http")
     	)
            .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
                @Override
                public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) 		   {
                    return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
                }
            });

    RestHighLevelClient esClient = new RestHighLevelClient(builder);

    SearchRequest searchRequest = new SearchRequest("my_index");
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.query(QueryBuilders.matchAllQuery());
    searchRequest.source(searchSourceBuilder);

    SearchResponse searchResponse = esClient.search(searchRequest);

And getting error:
Handler dispatch failed; nested exception is java.lang.BootstrapMethodError: java.lang.NoSuchMethodError: org.elasticsearch.action.search.SearchResponse.fromXContent(Lorg/elasticsearch/common/xcontent/XContentParser;)Lorg/elasticsearch/action/search/SearchResponse;

I have dependencies in maven:

   `<dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>elasticsearch-rest-high-level-client</artifactId>
        <version>6.3.2</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>6.3.2</version>
    </dependency>`

What can be wrong?

P.S. The old (low level) API works well for me

I am pretty sure that what you have in your classpath at runtime is not 6.3.2 but rather an older version that does not support parsing back responses. I am talking about the elasticsearch dependency. Can you check your classpath please? Seems like the code gets compiled right with the proper versions, but then at runtime something else is available.

Cheers
Luca

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.