# Can't get started with the ElasticSearch Java API classes

**URL:** <https://discuss.elastic.co/t/cant-get-started-with-the-elasticsearch-java-api-classes/320951>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [December 10, 2022, 3:49pm UTC](https://discuss.elastic.co/t/cant-get-started-with-the-elasticsearch-java-api-classes/320951 "2022-12-10T15:49:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alain\_Desilets](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alain_desilets/32/29314_2.png) [@Alain\_Desilets](https://discuss.elastic.co/u/Alain_Desilets)\
**Post date:** [December 10, 2022, 3:49pm UTC](https://discuss.elastic.co/t/cant-get-started-with-the-elasticsearch-java-api-classes/320951/1 "2022-12-10T15:49:06Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/index.html)

I install it as instructed [here](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/installation.html), i.e., I put this in my pom.xml file:

```auto
    <dependency>
      <groupId>co.elastic.clients</groupId>
      <artifactId>elasticsearch-java</artifactId>
      <version>8.5.3</version>
    </dependency>

```

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:](https://repo.maven.apache.org/maven2))

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](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/connecting.html), 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](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/java-rest-low.html).

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

```auto
		<dependency>
			 <groupId>org.elasticsearch.client</groupId>
			 <artifactId>elasticsearch-rest-client</artifactId>
			 <version>8.5.2</version>
		</dependency>

```

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.

Thx.

---

<div class="post-metadata">

**Author:** ![Alain\_Desilets](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alain_desilets/32/29314_2.png) [@Alain\_Desilets](https://discuss.elastic.co/u/Alain_Desilets)\
**Post date:** [December 12, 2022, 3:28pm UTC](https://discuss.elastic.co/t/cant-get-started-with-the-elasticsearch-java-api-classes/320951/2 "2022-12-12T15:28:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![swallez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/swallez/32/11972_2.png) [@swallez](https://discuss.elastic.co/u/swallez)\
**Post date:** [December 15, 2022, 10:10am UTC](https://discuss.elastic.co/t/cant-get-started-with-the-elasticsearch-java-api-classes/320951/3 "2022-12-15T10:10:02Z")

</div>

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](https://search.maven.org/artifact/co.elastic.clients/elasticsearch-java/8.5.3/jar)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 12, 2023, 10:10am UTC](https://discuss.elastic.co/t/cant-get-started-with-the-elasticsearch-java-api-classes/320951/4 "2023-01-12T10:10:34Z")

</div>

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