Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elasticsearch Java Client #22622

Merged
merged 1 commit into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/native-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
},
{
"category": "Data6",
"timeout": 70,
"test-modules": "elasticsearch-rest-client, elasticsearch-rest-high-level-client, hibernate-search-orm-elasticsearch, hibernate-search-orm-elasticsearch-tenancy, hibernate-search-orm-opensearch, hibernate-search-orm-elasticsearch-coordination-outbox-polling, hibernate-reactive-panache, hibernate-reactive-panache-kotlin",
"timeout": 80,
"test-modules": "elasticsearch-rest-client, elasticsearch-rest-high-level-client, elasticsearch-java-client, hibernate-search-orm-elasticsearch, hibernate-search-orm-elasticsearch-tenancy, hibernate-search-orm-opensearch, hibernate-search-orm-elasticsearch-coordination-outbox-polling, hibernate-reactive-panache, hibernate-reactive-panache-kotlin",
"os-name": "ubuntu-latest"
},
{
Expand Down
22 changes: 22 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,16 @@
<artifactId>quarkus-elasticsearch-rest-high-level-client-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-java-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-java-client-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-security</artifactId>
Expand Down Expand Up @@ -5142,6 +5152,18 @@
<artifactId>elasticsearch-rest-client</artifactId>
<version>${elasticsearch-opensource-components.version}</version>
</dependency>
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>${elasticsearch-opensource-components.version}</version>
<!-- exclude log4j2 to get its version from log4j2-jboss-logmanager -->
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public enum Feature {
ELASTICSEARCH_REST_CLIENT_COMMON,
ELASTICSEARCH_REST_CLIENT,
ELASTICSEARCH_REST_HIGH_LEVEL_CLIENT,
ELASTICSEARCH_JAVA_CLIENT,
FLYWAY,
GRPC_CLIENT,
GRPC_SERVER,
Expand Down
13 changes: 13 additions & 0 deletions devtools/bom-descriptor-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-java-client</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-rest-client</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-java-client-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-rest-client-deployment</artifactId>
Expand Down
58 changes: 58 additions & 0 deletions extensions/elasticsearch-java-client/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-java-client-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-elasticsearch-java-client-deployment</artifactId>
<name>Quarkus - Elasticsearch Java client - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-rest-client-common-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-rest-client-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-java-client</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.quarkus.elasticsearch.javaclient.deployment;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.elasticsearch.javaclient.runtime.ElasticsearchJavaClientProducer;

class ElasticsearchJavaClientProcessor {

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(Feature.ELASTICSEARCH_JAVA_CLIENT);
}

@BuildStep
AdditionalBeanBuildItem build() {
return AdditionalBeanBuildItem.unremovableOf(ElasticsearchJavaClientProducer.class);
}

@BuildStep
RuntimeInitializedClassBuildItem runtimeInitializedClass() {
return new RuntimeInitializedClassBuildItem("org.elasticsearch.client.RequestOptions");
}

@BuildStep
ServiceProviderBuildItem serviceProvider() {
return new ServiceProviderBuildItem("jakarta.json.spi.JsonProvider",
"co.elastic.clients.json.jackson.JacksonJsonProvider");
}

@BuildStep
ReflectiveClassBuildItem reflectiveClass() {
return ReflectiveClassBuildItem.builder("org.eclipse.parsson.JsonProviderImpl").build();
}

}
23 changes: 23 additions & 0 deletions extensions/elasticsearch-java-client/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-extensions-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-elasticsearch-java-client-parent</artifactId>
<name>Quarkus - Elasticsearch Java client - Parent</name>
<packaging>pom</packaging>

<modules>
<module>deployment</module>
<module>runtime</module>
</modules>

</project>
80 changes: 80 additions & 0 deletions extensions/elasticsearch-java-client/runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-java-client-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-elasticsearch-java-client</artifactId>
<name>Quarkus - Elasticsearch Java client - Runtime</name>
<description>Connect to an Elasticsearch cluster using the Java client</description>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-rest-client-common</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>log4j2-jboss-logmanager</artifactId>
</dependency>

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


<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-maven-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>extension-descriptor</goal>
</goals>
<configuration>
<deployment>${project.groupId}:${project.artifactId}-deployment:${project.version}
</deployment>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.quarkus.elasticsearch.javaclient.runtime;

import java.io.IOException;
import java.io.UncheckedIOException;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Default;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;

import org.elasticsearch.client.RestClient;

import com.fasterxml.jackson.databind.ObjectMapper;

import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;

@ApplicationScoped
public class ElasticsearchJavaClientProducer {

@Inject
@Default
RestClient restClient;

@Inject
ObjectMapper objectMapper;

private ElasticsearchClient client;
private ElasticsearchAsyncClient asyncClient;
private ElasticsearchTransport transport;

@PostConstruct
void initTransport() {
this.transport = new RestClientTransport(restClient, new JacksonJsonpMapper(objectMapper));
}

@Produces
@Singleton
public ElasticsearchClient blockingClient() {
this.client = new ElasticsearchClient(this.transport);
return this.client;
}

@Produces
@Singleton
public ElasticsearchAsyncClient asyncClient() {
this.asyncClient = new ElasticsearchAsyncClient(this.transport);
return this.asyncClient;
}

@PreDestroy
void destroy() {
try {
if (this.transport != null) {
this.transport.close();
}
} catch (IOException ioe) {
throw new UncheckedIOException(ioe);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
artifact: ${project.groupId}:${project.artifactId}:${project.version}
name: "Elasticsearch Java Client"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice this before, but I think documentation is missing, do you think you could add a page?

It doesn't need to be extensive, even just stating what the extension is, what the entry point is (the client class), and including the configuration reference would be a start.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I planned to add a documentation and a quickstart later on but as this PR will be on ice for some time I'll do it in the same PR.

The documentation will be on the already existing Elasticsearch guide and I'll update the section about the high level client to explain that the java one is prefered.

metadata:
keywords:
- "elasticsearch"
- "full text"
- "search"
guide: "https://quarkus.io/guides/elasticsearch"
categories:
- "data"
# WARNING: Before leaving preview, we will need to discuss backwards compatibility.
# These clients are forward-compatible, not backward-compatible, quoting:
# > The Elasticsearch Java client is forward compatible; meaning that the client supports
# > communicating with greater or equal minor versions of Elasticsearch.
# > Elasticsearch language clients are only backwards compatible with default distributions
# > and without guarantees made.
# Source: https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/introduction.html
# This means that upgrading the version of the client in Quarkus will force users to upgrade their cluster.
# We will need to discuss whether this is acceptable and how to mitigate it.
status: "preview"
loicmathieu marked this conversation as resolved.
Show resolved Hide resolved
config:
- "quarkus.elasticsearch."
yrodiere marked this conversation as resolved.
Show resolved Hide resolved
Loading