I encountered a NoSuchMethodError when attempting to create an Elasticsearch client object in my Spring Boot Maven project. The error occurred specifically at the instantiation of the RestClientTransport object within the Elasticsearch Java API.
Error Message:
Exception in thread "main" java.lang.NoSuchMethodError: org.elasticsearch.client.RequestOptions$Builder.setHttpAsyncResponseConsumerFactory(Lorg/elasticsearch/client/HttpAsyncResponseConsumerFactory;)Lorg/elasticsearch/client/RequestOptions$Builder;
Code Snippet:
try {
RestClient restClient = RestClient.builder(
new HttpHost("localhost", 9200, "http")).build();
ElasticsearchTransport transport = new RestClientTransport(
restClient, new JacksonJsonpMapper());
ElasticsearchClient esClient = new ElasticsearchClient(transport);
System.out.println("ESClient "+esClient);
} catch(Exception ex) {
System.out.println("Unable to create Elasticsearch client: "+ ex);
// Handle exception appropriately
}
Java API client version
8.12.2
Java version
1.8.0_371
Elasticsearch Version
8.12.0
Problem description
I encountered a NoSuchMethodError when attempting to create an Elasticsearch client object in my Spring Boot Maven project. The error occurred specifically at the instantiation of the RestClientTransport object within the Elasticsearch Java API.
Error Message:
Code Snippet:
Imported Dependencies:
Environment Details:
Class Imports: