Can't get started with the ElasticSearch Java API classes

I am am having a hell of a time trying to get started with the ES Java API using the instructions on the official doc

I install it as instructed here, i.e., I put this in my pom.xml file:


But when I run mvn, it does not find the dependency:

Could not find artifact co.elastic.clients:elasticsearch-java:jar:8.5.3 in central (Central Repository:)

So I modify the dependency to use 8.5.2 (which as I understand is the latest stable version). This time, maven does find the dependency, but when I write code that tries to connect to ES as per this page, maven complains that it can't find the RestClient class.

After much searching and poking around, I notice a section way at the end of the official doc about the Low level Rest API.

So I follow the instructions there and add this to my pom.xml:


This time, Maven finds the RestClient class.

SUGGESTION: This dependency really should be mentioned at the BEGINNING of the doc, not the very end. It took me several hours of poking around before I noticed that.

But I am not out of the woods yet, because even though the program compiles with Mavenm, when I try to run it, I get:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpHost

Please help.


Nevermind. The Class not found error was a problem with the way I was packaging my app.

So, in summary, to get started:

  • Don't use the latest version of elasticearch-java because there doesn't seem to be a Maven artifact for that versoin.
  • Include dependency elasticsearch-rest-client as well as elastic-java

There was indeed a delay in publishing version 8.5.3 to Maven Central, which explains the initial error and why you had to fall back to 8.5.2.

Now you should normally not have to add the elasticsearch-rest-client as it's listed as a dependency in the POM: Maven Central Repository Search

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