-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Elasticsearch Java Client #22622
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
40 changes: 40 additions & 0 deletions
40
...java/io/quarkus/elasticsearch/javaclient/deployment/ElasticsearchJavaClientProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
68 changes: 68 additions & 0 deletions
68
...ain/java/io/quarkus/elasticsearch/javaclient/runtime/ElasticsearchJavaClientProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...ions/elasticsearch-java-client/runtime/src/main/resources/META-INF/quarkus-extension.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
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
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.