Skip to content
Open
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
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/dev-services.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ The Elasticsearch Dev Service will be enabled when one of the Elasticsearch base
is present in your application, and the server address has not been explicitly configured.
More information can be found in the xref:elasticsearch-dev-services.adoc[Elasticsearch Dev Services Guide].

include::{generated-dir}/config/quarkus-elasticsearch-rest-client_quarkus.elasticsearch.devservices.adoc[opts=optional, leveloffset=+1]
include::{generated-dir}/config/quarkus-elasticsearch-rest-client_quarkus.elasticsearch.adoc[opts=optional, leveloffset=+1]

=== Observability

Expand Down
17 changes: 12 additions & 5 deletions docs/src/main/asciidoc/elasticsearch-dev-services.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ include::_attributes.adoc[]
:categories: data
:summary: Start Elasticsearch automatically in dev and test modes
:topics: data,search,elasticsearch,nosql,dev-services,testing,dev-mode
:extensions: io.quarkus:quarkus-elasticsearch-java-client,io.quarkus:quarkus-elasticsearch-rest-client,io.quarkus:quarkus-hibernate-search-orm-elasticsearch
:extensions: io.quarkus:quarkus-elasticsearch-java-client,io.quarkus:quarkus-elasticsearch-rest-client,io.quarkus:quarkus-hibernate-search-orm-elasticsearch,io.quarkus:quarkus-hibernate-search-standalone-elasticsearch

If any Elasticsearch-related extension is present (e.g. `quarkus-elasticsearch-rest-client` or `quarkus-hibernate-search-orm-elasticsearch`),
If any Elasticsearch-related extension is present (e.g. `quarkus-elasticsearch-rest-client`, `quarkus-hibernate-search-orm-elasticsearch` or `quarkus-hibernate-search-standalone-elasticsearch`),
Dev Services for Elasticsearch automatically starts an Elasticsearch server in dev mode and when running tests.
So, you don't have to start a server manually.
The application is configured automatically.
Expand All @@ -24,6 +24,7 @@ Dev Services for Elasticsearch is automatically enabled unless:
- the hosts property is configured, depending on the extension used it can be:
- `quarkus.elasticsearch.hosts`
- `quarkus.hibernate-search-orm.elasticsearch.hosts`
- `quarkus.hibernate-search-standalone.elasticsearch.hosts`

Dev Services for Elasticsearch relies on Docker to start the server.
If your environment does not support Docker, you will need to start the server manually, or connect to an already running server.
Expand Down Expand Up @@ -138,13 +139,19 @@ In that case, you will need to stop and remove these containers manually.
If you want to reuse containers for some Quarkus applications but not all of them,
or some Dev Services but not all of them,
you can disable this feature for a specific Dev Service by setting the configuration property
xref:elasticsearch-dev-services.adoc#quarkus-elasticsearch-rest-client_quarkus-elasticsearch-devservices_quarkus-elasticsearch-devservices-reuse[`quarkus.elasticsearch.devservices.reuse`]
xref:elasticsearch-dev-services.adoc#quarkus-elasticsearch-rest-client_quarkus-elasticsearch-devservices-reuse[`quarkus.elasticsearch.devservices.reuse`]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the achhors for config devservices properties changed here... but I'm not sure what exactly contributed to that 😕 , or if maybe it's ok to have the new anchor moving forward ?

to `false`.

== Multiple Elasticsearch service instances

Dev services for Elasticsearch can start multiple instances as necessary.
Currently, this is only compatible with the `quarkus-elasticsearch-rest-client` extension.
A separate Dev Service will be started for each named Elasticsearch REST client.

== Current limitations

Currently, only the default backend for Hibernate Search Elasticsearch is supported, because Dev Services for Elasticsearch can only start one Elasticsearch container.
Currently, only the default backend for Hibernate Search Elasticsearch is supported.

== Configuration reference

include::{generated-dir}/config/quarkus-elasticsearch-rest-client_quarkus.elasticsearch.devservices.adoc[opts=optional, leveloffset=+1]
include::{generated-dir}/config/quarkus-elasticsearch-rest-client_quarkus.elasticsearch.adoc[opts=optional, leveloffset=+1]
97 changes: 95 additions & 2 deletions docs/src/main/asciidoc/elasticsearch.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,19 @@ Classes marked with `@ElasticsearchClientConfig` are made application scoped CDI
You can override the scope at the class level if you prefer a different scope.
====

[NOTE]
====
When configuring the <<named-clients,named clients>> with `@ElasticsearchClientConfig`
pass the name of the client to configure through the `value` attribute:
[source,java]
----
@ElasticsearchClientConfig("second-client")
public class AnotherClientConfigurer implements RestClientBuilder.HttpClientConfigCallback {
// ...
}
----
====

== Running an Elasticsearch cluster

As by default, the Elasticsearch client is configured to access a local Elasticsearch cluster on port 9200 (the default Elasticsearch port),
Expand Down Expand Up @@ -568,13 +581,84 @@ public class FruitService {
<3> We directly pass the object to the request as the Java API client has a serialization layer.
<4> We send the request to Elasticsearch.

[[named-clients]]
== Named Elasticsearch clients

The Elasticsearch REST client extension allows configuring multiple clients that communicate to different Elasticsearch clusters
within the same application.

This is achieved through the named Elasticsearch clients:

[source,java]
----

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import org.elasticsearch.client.RestClient;
import io.smallrye.common.annotation.Identifier;

@ApplicationScoped
public class FruitService {
@Inject
@Identifier("second-elasticsearch-cluster") // <1>
RestClient restClient;

// ...
}
----
<1> We specify the name of the client through the `@Identifier` when injecting a `RestClient` within the service.

Named Elasticsearch REST clients in this case can be configured as follows:

[source,properties]
----
# configure the second Elasticsearch client
quarkus.elasticsearch."second-elasticsearch-cluster".hosts=second-elasticsearch:9200
----

It is also possible to use the named higher level Elasticsearch clients.
The name of such client *must* match an existing, configured lower-level REST client.

[source,java]
----

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import io.smallrye.common.annotation.Identifier;

@ApplicationScoped
public class FruitService {
@Inject
@Identifier("second-elasticsearch-cluster") // <1>
ElasticsearchClient client;

// ...
}
----
<1> We specify the name of the client through the `@Identifier` when injecting a `ElasticsearchClient` within the service.

[NOTE]
====
While Quarkus will attempt to find all the named clients at the build time and prepare the required resources for them,
in some cases, e.g. when the client is only accessed programmatically, it might not be possible to discover all of them.
To ensure that all clients are correctly processed, you can use the `quarkus.elasticsearch.[client name].force-discovery`
configuration property for each required client name.

Those clients defined at the build time that won't be necessary at runtime can be <<client-active,deactivated>>.
====

== Hibernate Search Elasticsearch

Quarkus supports Hibernate Search with Elasticsearch via the `quarkus-hibernate-search-orm-elasticsearch` extension.
Quarkus supports Hibernate Search with Elasticsearch via the `quarkus-hibernate-search-orm-elasticsearch`
and `quarkus-hibernate-search-standalone-elasticsearch` extensions.

Hibernate Search Elasticsearch allows to synchronize your Jakarta Persistence entities to an Elasticsearch cluster and offers a way to query your Elasticsearch cluster using the Hibernate Search API.

If you are interested in it, please consult the xref:hibernate-search-orm-elasticsearch.adoc[Hibernate Search with Elasticsearch guide].
If you are interested in it, please consult one of the following guides: xref:hibernate-search-orm-elasticsearch.adoc[Hibernate Search with ORM and Elasticsearch]
or xref:hibernate-search-standalone-elasticsearch.adoc[Hibernate Search standalone with Elasticsearch].

== Cluster Health Check

Expand All @@ -598,6 +682,15 @@ Running it is as simple as executing `./target/elasticsearch-low-level-client-qu

You can then point your browser to `http://localhost:8080/fruits.html` and use your application.

[[client-active]]
=== Activate/deactivate clients

In some cases it may be useful to deactivate some of the REST clients detected at build time.
To deactivate a client at runtime, set the `quarkus.elasticsearch[.optional client name].active` (for the low-level Elasticsearch REST client)
or `quarkus.elasticsearch-java[.optional client name].active` (for the Java Elasticsearch client) to `false`.
Deactivating a low-level Elasticsearch REST client automatically deactivate the corresponding Java Elasticsearch client,
since it is using the low-level one as its transport for communication with the cluster.

== Conclusion

Accessing an Elasticsearch cluster from the low level REST client or the Elasticsearch Java client is easy with Quarkus as it provides easy configuration, CDI integration and native support for it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ private Optional<ContainerPort> getMappedPort(Container container, int port) {
}

public Optional<ContainerAddress> locateContainer(String serviceName, boolean shared, LaunchMode launchMode) {
return locateContainer(serviceName, shared, launchMode, ContainerLocator::anyContainerAddress);
}

public Optional<ContainerAddress> locateContainer(String serviceName, boolean shared, LaunchMode launchMode,
Predicate<ContainerAddress> filter) {
if (shared && launchMode == LaunchMode.DEVELOPMENT) {
return lookup(serviceName)
.flatMap(container -> getMappedPort(container, port).stream()
Expand All @@ -89,6 +94,7 @@ public Optional<ContainerAddress> locateContainer(String serviceName, boolean sh
containerAddress.getUrl());
return containerAddress;
}).stream()))
.filter(filter)
.findFirst();
} else {
return Optional.empty();
Expand Down Expand Up @@ -133,4 +139,8 @@ public Optional<Integer> locatePublicPort(String serviceName, boolean shared, La
return Optional.empty();
}
}

private static boolean anyContainerAddress(ContainerAddress ca) {
return true;
}
}
33 changes: 33 additions & 0 deletions extensions/elasticsearch-java-client/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-java-client</artifactId>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -55,8 +61,35 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>test-elasticsearch</id>
<activation>
<property>
<name>test-containers</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>


</project>
Loading
Loading