Platform.sh User Documentation

How to Deploy Quarkus on Platform.sh with Elasticsearch

Upsun Beta

Access our newest offering - Upsun!

Get your free trial by clicking the link below.

Get your Upsun free trial

Quarkus provides two ways of accessing Elasticsearch: via the lower level RestClient or via the RestHighLevelClient. To initialize Elasticsearch in your project’s cluster so that it can be accessed by a Quarkus application, it is necessary to modify two files.

1. Add the Elasticsearch service Anchor to this heading

In your service configuration, include Elasticsearch with a valid supported version:

.platform/services.yaml
elasticsearch:
    type: elasticsearch:8.5
    disk: 256

2. Add the Elasticsearch relationship Anchor to this heading

In your app configuration, use the service name searchelastic to grant the application access to Elasticsearch via a relationship:

.platform.app.yaml
relationships:
    essearch: "elasticsearch:elasticsearch"

3. Export connection credentials to the environment Anchor to this heading

Connection credentials for Elasticsearch, like any service, are exposed to the application container through the PLATFORM_RELATIONSHIPS environment variable from the deploy hook onward. Since this variable is a base64 encoded JSON object of all of your project’s services, you’ll likely want a clean way to extract the information specific to Elasticsearch into it’s own environment variables that can be used by Quarkus. On Platform.sh, custom environment variables can be defined programmatically in a .environment file using jq to do just that:

export ES_HOST=$(echo $PLATFORM_RELATIONSHIPS | base64 --decode | jq -r ".essearch[0].host")
export ES_PORT=$(echo $PLATFORM_RELATIONSHIPS | base64 --decode | jq -r ".essearch[0].port")
export QUARKUS_HIBERNATE_SEARCH_ELASTICSEARCH_HOSTS=${ES_HOST}:${ES_PORT}
export QUARKUS_HTTP_PORT=$PORT
export JAVA_OPTS="-Xmx$(jq .info.limits.memory /run/config.json)m -XX:+ExitOnOutOfMemoryError"

4. Connect to Elasticsearch Anchor to this heading

Commit that code and push. The Elasticsearch instance is ready to be connected from within the Quarkus application.

Is this page helpful?