Installation

edit

Requirements:

  • Java 8 or later.
  • A JSON object mapping library to allow seamless integration of your application classes with the Elasticsearch API. The Java client has support for Jackson or a JSON-B library like Eclipse Yasson.

Releases are hosted on Maven Central. If you are looking for a SNAPSHOT version, the Elastic Maven Snapshot repository is available at https://snapshots.elastic.co/maven/.

Installation in a Gradle project by using Jackson

edit
dependencies {
    implementation 'co.elastic.clients:elasticsearch-java:7.17.24'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.0'
}

Installation in a Maven project by using Jackson

edit

In the pom.xml of your project, add the following repository definition and dependencies:

<project>
  <dependencies>

    <dependency>
      <groupId>co.elastic.clients</groupId>
      <artifactId>elasticsearch-java</artifactId>
      <version>7.17.24</version>
    </dependency>

    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.17.0</version>
    </dependency>

  </dependencies>
</project>

If you get ClassNotFoundException: jakarta.json.spi.JsonProvider

edit

It may happen that after setting up the dependencies, your application fails with ClassNotFoundException: jakarta.json.spi.JsonProvider.

If this happens, you have to explicitly add the jakarta.json:jakarta.json-api:2.0.1 dependency.

Gradle:

dependencies {
    ...
    implementation 'jakarta.json:jakarta.json-api:2.0.1'
}

Maven:

<project>
  <dependencies>
    ...
    <dependency>
      <groupId>jakarta.json</groupId>
      <artifactId>jakarta.json-api</artifactId>
      <version>2.0.1</version>
    </dependency>

  </dependencies>
</project>

Why is this needed?

Some frameworks like Spring Boot or Helidon come with their Gradle and Maven plugins or their Maven BOM files to ease development and dependency management. These plugins and BOM define the versions to use for a number of well-known libraries.

One these libraries can be jakarta.json:json-api that defines the standard Java JSON API. In version 1.x this library used the javax.json package, while in version 2.x it uses the jakarta.json package after the transition from JavaEE to JakartaEE.

The Java API Client depends on version 2.0.1 of this library, in order to use the newer and future-proof jakarta.json package. But some build plugins and BOMs override the Java API Client’s dependency to use version 1.x in the older javax.json namespace, resulting in ClassNotFoundException: jakarta.json.spi.JsonProvider.

Adding the correct version as top-level project dependency solves the problem.

If your application also requires javax.json you can add the javax.json:javax.json-api:1.1.4 dependency, which is equivalent to jakarta.json:jakarta.json-api:1.1.6.