I am trying to access Amazon Elasticsearch instance using the RestHighLevelClient
from a java program. Below is my code:
AWS4Signer signer = new AWS4Signer();
signer.setServiceName("es");
signer.setRegionName("us-east-1");
HttpRequestInterceptor interceptor = new AWSRequestSigningApacheInterceptor("es", signer, creds);
RestHighLevelClient EsClient = new RestHighLevelClient(RestClient.builder(new HttpHost("hostname.us-east-1.es.amazonaws.com",443,"https"))
.setHttpClientConfigCallback(httpAsyncClientBuilder -> HttpAsyncClientBuilder
.create()
.addInterceptorLast(interceptor)));
When I run this code, I am seeing this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/elasticsearch/script/mustache/SearchTemplateRequest
at Main.main(Main.java:194)
Caused by: java.lang.ClassNotFoundException: org.elasticsearch.script.mustache.SearchTemplateRequest
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
This is happening at the initialization of EsClient
. The error indicates a missing dependency, but I do have org.elasticsearch.script
in my classpath. However, it doesn't seem to have the mustache.SearchTemplateRequest
. Below are the relevant dependencies I have added to the project:
Not sure what I am missing here. Any help would be appreciated. Thank you.
I was missing the below jar:
<!-- https://mvnrepository.com/artifact/org.elasticsearch.plugin/lang-mustache-client -->
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>lang-mustache-client</artifactId>
<version>7.6.2</version>
</dependency>
There were several other jars that I had to add to finally get it working.