Quarkus Opensearch Extension

The quarkus-opensearch extension allows you to connect to an OpenSearch cluster using the clients provided by the OpenSearch project.

OpenSearch Clients

OpenSearch provides three different flavours of clients for connecting to the cluster. This extension has support for all three of them.

OpenSearch Java Client

This is the latest implementation of the OpenSearch clients, when starting a new project you should use this client and not bother about the others. This will be the only OpenSearch Client supported in the future. Just like the OpenSearch REST high-level level, the OpenSearch Java client lets you interact with OpenSearch through Java methods and data structures. In comparison to the REST high-level, it has no dependency to org.opensearch:opensearch and also provides an async client implementation.

Deprecation

The OpenSearch REST clients are deprecated. Support will be removed in OpenSearch version 3.0.0.

It is recommended to switch to the Java client. We will try to support the REST clients as long as possible, but if you start a new project this is not the client you should use anymore.

OpenSearch REST High-Level Client

The OpenSearch Java high-level REST client lets you interact with your OpenSearch clusters and indices through Java methods and data structures rather than HTTP methods and JSON.

OpenSearch REST (low-level) client

Core low-level client which lets you interact with OpenSearch clusters through HTTP methods and JSON, it is also used by the two other higher level clients for connecting to the cluster.

Installation

OpenSearch Java client

The java client does not have any dependencies on the REST client. All clients are sharing most of the configuration properties. The AWS related configuration properties quarkus.opensearch.aws.* are only applicable to this java client.

If you want to use this client all you need to do is add the io.quarkiverse.opensearch:quarkus-opensearch-java-client extension first to your build file.

with Maven, add the following dependency to your POM file:

<dependency>
    <groupId>io.quarkiverse.opensearch</groupId>
    <artifactId>quarkus-opensearch-java-client</artifactId>
    <version>2.0.0.CR1</version>
</dependency>

Transport Provider (Required)

The Java client requires a transport provider to communicate with OpenSearch. You must add one of the following transport dependencies:

<!-- Apache HttpClient5 (recommended for most use cases) -->
<dependency>
  <groupId>io.quarkiverse.opensearch</groupId>
  <artifactId>quarkus-opensearch-transport-apache</artifactId>
</dependency>

Or for AWS OpenSearch Service:

<!-- AWS SDK2 (for AWS OpenSearch Service) -->
<dependency>
  <groupId>io.quarkiverse.opensearch</groupId>
  <artifactId>quarkus-opensearch-transport-aws</artifactId>
</dependency>

If no transport provider is found, the application will fail at runtime with: IllegalStateException: No OpenSearchTransportProvider found for config

Configuring Additional Named Clients

This extension supports defining and injecting multiple named OpenSearch clients, useful when your application needs to connect to different OpenSearch clusters (e.g., for analytics, logging, or operational data).

A named client can be configured using quarkus.opensearch."client-name".*.

Example: Default and Additional Client
# Default client (unnamed)
quarkus.opensearch.hosts=localhost:9200

# Additional client named "analytics"
quarkus.opensearch.analytics.hosts=analytics-cluster.internal:9200
quarkus.opensearch.analytics.username=some-user
quarkus.opensearch.analytics.password=some-password
quarkus.opensearch.analytics.aws.region=us-west-2
Injecting the Default Client

If you’re using only a single OpenSearch cluster, you can inject the default client without any qualifiers:

import jakarta.inject.Inject;
import org.opensearch.client.opensearch.OpenSearchClient;

public class MyService {

    @Inject
    OpenSearchClient defaultClient;

    public void run() {
        // Use the defaultClient to interact with OpenSearch
    }
}
Injecting Named Clients in Your Code

To use a named client in your application, inject it using the @OpenSearchClientName qualifier:

import jakarta.inject.Inject;
import io.quarkiverse.opensearch.OpenSearchClientName;
import org.opensearch.client.opensearch.OpenSearchClient;

public class ReportService {

    @Inject
    @OpenSearchClientName("analytics")
    OpenSearchClient analyticsClient;

    public void runQuery() {
        // Use the analyticsClient to run a search
    }
}

The @OpenSearchClientName("<client-name>") injection is only supported for the OpenSearch Java Client module.

OpenSearch REST High-Level Client

The REST High-Level Client depends on the REST client and does not require any additional configuration.

If you want to use this client all you need to do is add the io.quarkiverse.opensearch:quarkus-opensearch-rest-high-level-client extension first to your build file.

with Maven, add the following dependency to your POM file:

<dependency>
    <groupId>io.quarkiverse.opensearch</groupId>
    <artifactId>quarkus-opensearch-rest-high-level-client</artifactId>
    <version>2.0.0.CR1</version>
</dependency>

OpenSearch REST Low-Level Client

If you want to use this extension, you need to add the io.quarkiverse.opensearch:quarkus-opensearch-rest-client extension first to your build file.

For instance, with Maven, add the following dependency to your POM file:

<dependency>
    <groupId>io.quarkiverse.opensearch</groupId>
    <artifactId>quarkus-opensearch-rest-client</artifactId>
    <version>2.0.0.CR1</version>
</dependency>

Configuring Opensearch

The main property to configure is the URL to connect to the Opensearch cluster.

For a typical clustered Opensearch service, a sample configuration would look like the following:

# configure the Elasticsearch client for a cluster of two nodes
quarkus.opensearch.hosts = opensearch-01:9200,opensearch-02:9200

In this case, we are using a single instance running on localhost:

# configure the Opensearch client for a single instance on localhost
quarkus.opensearch.hosts = localhost:9200

If you need a more advanced configuration, you can find the comprehensive list of supported configuration properties at the end of this guide.

Dev Services

Quarkus supports a feature called Dev Services that allows you to start various containers without any config. In the case of Opensearch, this support extends to the default Opensearch connection. What that means practically is that, if you have not configured quarkus.opensearch.hosts, Quarkus will automatically start an Opensearch container when running tests or dev mode, and automatically configure the connection.

When running the production version of the application, the Opensearch connection needs to be configured as usual, so if you want to include a production database config in your application.properties and continue to use Dev Services we recommend that you use the %prod. profile to define your Opensearch settings.

Extension Configuration Reference

Configuration property fixed at build time - All other configuration properties are overridable at runtime

Configuration property

Type

Default

Whether a health check is published in case the smallrye-health extension is present.

Environment variable: QUARKUS_OPENSEARCH_HEALTH_ENABLED

boolean

true

If Dev Services for OpenSearch has been explicitly enabled or disabled. Dev Services are generally enabled by default, unless there is an existing configuration present. For OpenSearch, Dev Services starts a server unless quarkiverse.opensearch.hosts is set.

Environment variable: QUARKUS_OPENSEARCH_DEVSERVICES_ENABLED

boolean

Optional fixed port the dev service will listen to.

If not defined, the port will be chosen randomly.

Environment variable: QUARKUS_OPENSEARCH_DEVSERVICES_PORT

int

The OpenSearch container image to use. Defaults to the opensearch image provided by OpenSearch.

Environment variable: QUARKUS_OPENSEARCH_DEVSERVICES_IMAGE_NAME

string

docker.io/opensearchproject/opensearch:2.19.2

The value for the OPENSEARCH_JAVA_OPTS env variable. Defaults to setting the heap to 512MB min - 1GB max.

Environment variable: QUARKUS_OPENSEARCH_DEVSERVICES_JAVA_OPTS

string

-Xms512m -Xmx1g

Indicates if the OpenSearch server managed by Quarkus Dev Services is shared. When shared, Quarkus looks for running containers using label-based service discovery. If a matching container is found, it is used, and so a second one is not started. Otherwise, Dev Services for OpenSearch starts a new container.

The discovery uses the quarkus-dev-service-opensearch label. The value is configured using the service-name property.

Container sharing is only used in dev mode.

Environment variable: QUARKUS_OPENSEARCH_DEVSERVICES_SHARED

boolean

true

The value of the quarkus-dev-service-opensearch label attached to the started container. This property is used when shared is set to true. In this case, before starting a container, Dev Services for OpenSearch looks for a container with the quarkus-dev-service-opensearch label set to the configured value. If found, it will use this container instead of starting a new one. Otherwise it starts a new container with the quarkus-dev-service-opensearch label set to the specified value.

This property is used when you need multiple shared OpenSearch servers.

Environment variable: QUARKUS_OPENSEARCH_DEVSERVICES_SERVICE_NAME

string

opensearch

quarkus.opensearch."client-name".hosts

The list of hosts of the OpenSearch servers, when accessing AWS OpenSearch set to AWS endpoint name. Host Example: opensearch-01:9200,opensearch-02:9200 AWS Endpoint Example: search-domain-name-identifier.region.es.amazonaws.com

Environment variable: QUARKUS_OPENSEARCH_HOSTS

list of string

quarkus.opensearch."client-name".protocol

The protocol to use when contacting OpenSearch servers. Set to "https" to enable SSL/TLS.

Environment variable: QUARKUS_OPENSEARCH_PROTOCOL

string

http

quarkus.opensearch."client-name".username

The username for basic HTTP authentication.

Environment variable: QUARKUS_OPENSEARCH_USERNAME

string

quarkus.opensearch."client-name".password

The password for basic HTTP authentication.

Environment variable: QUARKUS_OPENSEARCH_PASSWORD

string

quarkus.opensearch."client-name".connection-timeout

The connection timeout.

Environment variable: QUARKUS_OPENSEARCH_CONNECTION_TIMEOUT

Duration 

15S

quarkus.opensearch."client-name".thread-timeout

The connection timeout.

Environment variable: QUARKUS_OPENSEARCH_THREAD_TIMEOUT

Duration 

30S

quarkus.opensearch."client-name".socket-timeout

The socket timeout.

Environment variable: QUARKUS_OPENSEARCH_SOCKET_TIMEOUT

Duration 

30S

quarkus.opensearch."client-name".max-connections

The maximum number of connections to all the OpenSearch servers.

Environment variable: QUARKUS_OPENSEARCH_MAX_CONNECTIONS

int

20

quarkus.opensearch."client-name".max-connections-per-route

The maximum number of connections per OpenSearch server.

Environment variable: QUARKUS_OPENSEARCH_MAX_CONNECTIONS_PER_ROUTE

int

10

quarkus.opensearch."client-name".io-thread-counts

The number of IO thread. By default, this is the number of locally detected processors.

Thread counts higher than the number of processors should not be necessary because the I/O threads rely on non-blocking operations, but you may want to use a thread count lower than the number of processors.

Environment variable: QUARKUS_OPENSEARCH_IO_THREAD_COUNTS

int

quarkus.opensearch."client-name".aws.region

AWS Region

Environment variable: QUARKUS_OPENSEARCH_AWS_REGION

string

us-west-2

quarkus.opensearch."client-name".aws.service

Set to "es" or "aoss" to use AWS OpenSearch Service. es : Amazon OpenSearch Service aoss : Amazon OpenSearch Serverless

Environment variable: QUARKUS_OPENSEARCH_AWS_SERVICE

string

quarkus.opensearch."client-name".aws.access-key-id

AWS Secret Access Key for setting up StaticCredentialsProvider

Environment variable: QUARKUS_OPENSEARCH_AWS_ACCESS_KEY_ID

string

quarkus.opensearch."client-name".aws.access-key-secret

AWS Secret Access Key Secret for setting up StaticCredentialsProvider

Environment variable: QUARKUS_OPENSEARCH_AWS_ACCESS_KEY_SECRET

string

quarkus.opensearch."client-name".tls.tls-configuration-name

The name of the TLS configuration to use. This refers to a configuration group defined under quarkus.tls.*. If not set, no explicit TLS configuration will be applied beyond the default JDK behavior.

Environment variable: QUARKUS_OPENSEARCH_TLS_TLS_CONFIGURATION_NAME

string

required

quarkus.opensearch."client-name".discovery.enabled

Defines if automatic discovery is enabled.

Environment variable: QUARKUS_OPENSEARCH_DISCOVERY_ENABLED

boolean

false

quarkus.opensearch."client-name".discovery.refresh-interval

Refresh interval of the node list.

Environment variable: QUARKUS_OPENSEARCH_DISCOVERY_REFRESH_INTERVAL

Duration 

5M

quarkus.opensearch."client-name".ssl.key-store-file

This property is deprecated since 2.0.0.

Optional keyStoreFile to be used when connecting to cluster nodes

Environment variable: QUARKUS_OPENSEARCH_SSL_KEY_STORE_FILE

string

quarkus.opensearch."client-name".ssl.key-store-password

This property is deprecated since 2.0.0.

Optional password for accessing keyStoreFile

Environment variable: QUARKUS_OPENSEARCH_SSL_KEY_STORE_PASSWORD

string

quarkus.opensearch."client-name".ssl.verify-hostname

This property is deprecated since 2.0.0.

SSL Verify Hostname

Environment variable: QUARKUS_OPENSEARCH_SSL_VERIFY_HOSTNAME

boolean

true

quarkus.opensearch."client-name".ssl.verify

This property is deprecated since 2.0.0.

Verify SSL Certificates

Environment variable: QUARKUS_OPENSEARCH_SSL_VERIFY

boolean

true

About the Duration format

To write duration values, use the standard java.time.Duration format. See the Duration#parse() Java API documentation for more information.

You can also use a simplified format, starting with a number:

  • If the value is only a number, it represents time in seconds.

  • If the value is a number followed by ms, it represents time in milliseconds.

In other cases, the simplified format is translated to the java.time.Duration format for parsing:

  • If the value is a number followed by h, m, or s, it is prefixed with PT.

  • If the value is a number followed by d, it is prefixed with P.