Elasticsearch
A single-node Elasticsearch container. Unlike every other module in this library, there is no no-arg constructor — see below.
Default image: none — an explicit image is required, e.g. elasticsearch:9.4.4Exposed ports: 9200 (REST, what the helpers here use), 9300 (transport) Wait strategy: Wait.forHttp("/").forPort(9200), 300s startup timeout Memory: withMemoryLimit(2560)Env: discovery.type=single-node, xpack.security.enabled=false, ES_JAVA_OPTS=-Xms512m -Xmx512m
| Member | Returns |
|---|---|
new ElasticsearchContainer(image) | Requires an explicit image — no default |
ElasticsearchContainer.start(image) | Promise<ElasticsearchContainer> — boots the container; image is required |
.restUrl | The REST API's base URL |
Example
ts
import { ElasticsearchContainer } from "rightsize/modules";
await using es = await ElasticsearchContainer.start("elasticsearch:9.4.4");
await fetch(`${es.restUrl}/books/_doc/1?refresh=true`, {
method: "PUT",
headers: { "content-type": "application/json" },
body: JSON.stringify({ title: "The Hobbit", author: "Tolkien" }),
});
const search = await fetch(`${es.restUrl}/books/_search`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ query: { match: { title: "Hobbit" } } }),
});
console.log(await search.text()); // the indexed document, in the hits arrayBackend notes
- No no-arg constructor — Elastic publishes no floating tag. Every other module in this library floats to the image's own
latest(or an equivalent) when no image is given. Elasticsearch has nothing to float to:elasticsearch:latest,elasticsearch:9, andelasticsearch:8are all 404 on Docker Hub — Elastic publishes only full version tags. This module was verified againstelasticsearch:9.4.4(arm64); both the constructor andstart()require an explicit image and have no default parameter. - Cluster health never reaches
greenon a single node. Elasticsearch's default replica count is one replica per index, and a single-node cluster has nowhere to assign a replica shard —/_cluster/healthreportsyellowindefinitely. A readiness check that waited forgreenwould hang until its own timeout; this module waits on a plain HTTP200from/instead, verified reached in 27s on a quiet local machine. The 300s startup timeout absorbs a loaded CI runner without masking a real hang. xpack.security.enabled=falsemeans the REST API answers plain HTTP with no TLS and no credentials — there is no username/password to configure or override here.- Memory:
withMemoryLimit(2560)— measured ~1.1 GB resident in a 2.48 GB guest at rest. - Compatibility check: the constructor only accepts images whose repository is
elasticsearch(registry host, tag, and digest stripped). A different repository throwsIncompatibleImageErrorbefore any backend call; override withDockerImageName.parse(image).asCompatibleSubstituteFor("elasticsearch")for a verified compatible fork or mirror.