Docker Compose Elasticsearch service and Java API Client 8.x startup readiness interoperability
0 reputation · 15 Oct 2021, 23:12 UTC
0 reputation · 15 Oct 2021, 23:12 UTC
A repeatable development environment is targeted using a Docker Compose Elasticsearch service with a pinned image tag and a named volume, together with an Elasticsearch Java API Client 8.x in the application build. The goal is consistent version alignment across developer machines for the cluster and the client library.
Version alignment is a documented constraint: the client major version should match the Elasticsearch major version for API compatibility, and the Docker image tag and client dependency are intended to be pinned in the project build file and compose definition. Network naming and container startup ordering are part of the integration boundary between Compose and the client.
The unresolved decision concerns readiness signaling. Docker Compose depends_on reflects container start, not cluster formation and shard allocation readiness. This creates uncertainty about when the Java API Client can safely issue requests in an automated test or application start sequence.
What signal defines Elasticsearch readiness for API calls in a Compose-based dev environment? How should version pinning be coordinated between the Docker image and the Java API Client dependency to maintain repeatability? What integration pattern avoids race conditions at the Compose to client boundary?
34775 reputation · 16 Oct 2021, 09:44 UTC
The signal that guarantees the cluster is ready for API calls in a Compose‑based dev environment is the /\_cluster/health endpoint returning a green (or, if acceptable, yellow) status. In Compose you expose this via a healthcheck on the elasticsearch service and then use depends_on: { condition: service_healthy } for the Java service. This ensures the Java client only starts after the cluster has allocated all primary shards and is reachable through the REST API.
depends_on is insufficientdepends_on waits for the container to start listening on the port, but not for shard allocation or cluster formation.Keep the Docker image tag and the Java client dependency in sync by defining a single version property or BOM. For example, if you use elasticsearch:8.14.3 in docker‑compose.yml, pin the Maven/Gradle dependency to 8.14.3:
// Maven example
<properties>
<elasticsearch.version>8.14.3</elasticsearch.version>
</properties>
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>${elasticsearch.version}</version>
</dependency>
Both the Compose file and the build file should reference the same property to avoid drift.
services:
elasticsearch:
image: elasticsearch:8.14.3
healthcheck:
test: ["CMD-SHELL", "curl -s -f http://localhost:9200/_cluster/health?wait_for_status=green || exit 1"]
interval: 10s
timeout: 5s
retries: 5
services:
app:
depends_on:
elasticsearch:
condition: service_healthy
/\_cluster/health.
docker compose up -d.
curl http://elasticsearch:9200/_cluster/health and verify the status field is "green".
client.ping()) and confirm it succeeds before the application proceeds.
Do you require the cluster to be fully green before the application starts, or is yellow acceptable for your test scenarios? Knowing that will dictate whether the health‑check query should wait for green or yellow.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.