The English version of quarkus.io is the official project site. Translated sites are community supported on a best-effort basis.

Dev Services for Elasticsearch

Elasticsearch関連のエクステンションがある場合(例: quarkus-elasticsearch-rest-clientquarkus-hibernate-search-orm-elasticsearch )、Dev Services for Elasticsearchは開発モードやテスト実行時に自動的にElasticsearchサーバを起動します。そのため、手動でサーバを起動する必要はありません。アプリケーションは自動的に設定されます。

Dev Services for Elasticsearchの有効化/無効化

Dev Services for Elasticsearchは、以下の場合を除き、自動的に有効化されます。

  • quarkus.devservices.enabledfalse に設定されている場合

  • quarkus.elasticsearch.devservices.enabledfalse に設定されている場合

  • hostsプロパティが設定されている場合。使用するエクステンションにより、次のいずれか:

  • quarkus.elasticsearch.hosts

  • quarkus.hibernate-search-orm.elasticsearch.hosts

Dev Services for Elasticsearchは、サーバーの起動にDockerを利用しています。Dockerに対応していない環境では、手動でサーバを起動するか、既に起動しているサーバに接続する必要があります。

共有Elasticsearch

アプリケーション間でサーバーを共有する必要がある場合があります。Dev Services for Elasticsearchは、 開発 モードで実行されている複数のQuarkusアプリケーションが1つのサーバーを共有できるように、 サービス検出 メカニズムを実装しています。

Dev Services for Elasticsearch は、コンテナの識別に使用される quarkus-dev-service-elasticsearch ラベルでコンテナを起動します。

複数の(共有)サーバーが必要な場合は、 quarkus.elasticsearch.devservices.service-name 属性を設定し、サーバー名を指定することができます。同じ値を持つコンテナを探すか、見つからない場合は新規に起動します。デフォルトのサービス名は elasticsearch です。

共有は、devモードではデフォルトで有効ですが、testモードでは無効です。共有は quarkus.elasticsearch.devservices.shared=false で無効にすることができます。

ポートの設定

デフォルトでは、Dev Services for Elasticsearchはランダムなポートを選び、アプリケーションを設定します。 quarkus.elasticsearch.devservices.port プロパティを設定することで、ポートを設定することができます。

Elasticsearchのhostsプロパティは、選択したポートで自動的に構成されることに注意してください。

イメージの設定

Dev Services for Elasticsearchは、ElasticsearchとOpenSearchの両方のイメージに基づいたディストリビューションをサポートしています。

When using Hibernate Search, Dev Services will default to Elasticsearch or OpenSearch based on Hibernate Search configuration.

そうでない場合、Dev ServicesはデフォルトでElasticsearchを使用します。OpenSearchを使用するには、ディストリビューションを明示的に設定してください:

quarkus.elasticsearch.devservices.distribution=opensearch

デフォルトとは異なるElasticsearchやOpenSearchのイメージを使用する必要がある場合は、以下の方法で設定することができます:

quarkus.elasticsearch.devservices.image-name=docker.io/elastic/elasticsearch:8.12.1

エキゾチックなイメージ名の場合、Quarkusはディストリビューションを推測できないことがあります( elastic または opensearch )。 このような場合、Dev Servicesの起動に失敗し、ディストリビューションを明示的に設定する必要があります:

quarkus.elasticsearch.devservices.image-name=my-custom-image-with-no-clue-about-the-distribution:1.0
quarkus.elasticsearch.devservices.distribution=elasticsearch

Dev Servicesの再利用

一般的なケース

Within a dev mode session or test suite execution, Quarkus will always reuse Elasticsearch Dev Services as long as their configuration (username, password, environment, port bindings, …​) did not change.

When the configuration of Elasticsearch Dev Services changes, Quarkus will always restart the corresponding containers.

When a dev mode session or test suite execution ends, Quarkus will (by default) stop Elasticsearch Dev Services.

実行を跨いだDev Servicesコンテナの再利用

If you want to keep Dev Service containers running after a dev mode session or test suite execution to reuse them in the next dev mode session or test suite execution, this is possible as well. Just enable TestContainers reuse by inserting this line in one of your TestContainers configuration file (generally ~/.testcontainers.properties or C:/Users/myuser/.testcontainers.properties):

testcontainers.reuse.enable=true

Even with container reuse enabled, containers will only be reused if their startup command did not change: same environment variables (username/password in particular), same port bindings, …​

Reusing containers implies reusing their internal state, including the Elasticsearch schema and the content of indexes.

If that’s not what you want — and if your tests write to the indexes, that’s probably not what you want — consider reinitializing your schema and data on application startup. If you use Hibernate Search, Hibernate Search’s schema management may help with that.

コンテナの再利用を有効にすると、新しいQuarkus開発モードセッションやテストスイートの実行を開始した後でも、古いコンテナ(特に実行可能ファイルが古い)が無期限に実行されたままになる可能性があります。

その場合、これらのコンテナを手動で停止して削除する必要があります。

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 quarkus.elasticsearch.devservices.reuse to false.

現在の制限事項

現在、Dev Services for Elasticsearchは1つのElasticsearchコンテナしか起動できないため、Hibernate Search Elasticsearchのデフォルトバックエンドのみがサポートされています。

設定リファレンス

ビルド時に固定される設定プロパティ - その他の設定プロパティは実行時にオーバーライド可能です。

Configuration property

デフォルト

Whether this Dev Service should start with the application in dev mode or tests.

Dev Services are enabled by default unless connection configuration (e.g. quarkus.elasticsearch.hosts) is set explicitly.

Environment variable: QUARKUS_ELASTICSEARCH_DEVSERVICES_ENABLED

Show more

boolean

Optional fixed port the dev service will listen to.

If not defined, the port will be chosen randomly.

Environment variable: QUARKUS_ELASTICSEARCH_DEVSERVICES_PORT

Show more

int

The Elasticsearch distribution to use.

Defaults to a distribution inferred from the explicitly configured image-name (if any), or by default to the distribution configured in depending extensions (e.g. Hibernate Search), or by default to elastic.

Environment variable: QUARKUS_ELASTICSEARCH_DEVSERVICES_DISTRIBUTION

Show more

elastic, opensearch

The Elasticsearch container image to use.

Defaults depend on the configured distribution:

  • For the elastic distribution: docker.io/elastic/elasticsearch:8.12.1

  • For the opensearch distribution: docker.io/opensearchproject/opensearch:2.11.1

Environment variable: QUARKUS_ELASTICSEARCH_DEVSERVICES_IMAGE_NAME

Show more

string

The value for the ES_JAVA_OPTS env variable.

Environment variable: QUARKUS_ELASTICSEARCH_DEVSERVICES_JAVA_OPTS

Show more

string

-Xms512m -Xmx1g

Whether the Elasticsearch 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 Elasticsearch starts a new container.

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

Container sharing is only used in dev mode.

Environment variable: QUARKUS_ELASTICSEARCH_DEVSERVICES_SHARED

Show more

boolean

true

The value of the quarkus-dev-service-elasticsearch 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 Elasticsearch looks for a container with the quarkus-dev-service-elasticsearch 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-elasticsearch label set to the specified value.

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

Environment variable: QUARKUS_ELASTICSEARCH_DEVSERVICES_SERVICE_NAME

Show more

string

elasticsearch

Whether to keep Dev Service containers running after a dev mode session or test suite execution to reuse them in the next dev mode session or test suite execution.

Within a dev mode session or test suite execution, Quarkus will always reuse Dev Services as long as their configuration (username, password, environment, port bindings, …​) did not change. This feature is specifically about keeping containers running when Quarkus is not running to reuse them across runs.

This feature needs to be enabled explicitly in testcontainers.properties, may require changes to how you configure data initialization in dev mode and tests, and may leave containers running indefinitely, forcing you to stop and remove them manually. See this section of the documentation for more information.

This configuration property is set to true by default, so it is mostly useful to disable reuse, if you enabled it in testcontainers.properties but only want to use it for some of your Quarkus applications.

Environment variable: QUARKUS_ELASTICSEARCH_DEVSERVICES_REUSE

Show more

boolean

true

Environment variables that are passed to the container.

Environment variable: QUARKUS_ELASTICSEARCH_DEVSERVICES_CONTAINER_ENV

Show more

Map<String,String>

関連コンテンツ