Skip to main content
The @healthzkit/elasticsearch package provides a HealthAdapter for the official @elastic/elasticsearch client. Each check calls cluster.health() and maps Elasticsearch cluster status to probe status: Transport or API errors return fail with the caught error. Install the adapter package and the peer client:
Peer: @elastic/elasticsearch >= 9.

Package entrypoints

  • @healthzkit/elasticsearch — elasticsearchAdapter and option types.
  • @healthzkit/elasticsearch/elasticsearch — elasticsearchAdapter only.
Both resolve to the same factory. Use the subpath when you want a dedicated entry for bundlers.

Shared options

BaseElasticsearchOptions: Pass either config or an existing client (not both).

elasticsearchAdapter

Each check runs client.cluster.health() and records round-trip latency in metadata.latencyMs, plus clusterStatus, clusterName, and numberOfNodes from the health response.

Config

Pass config as ClientOptions. The adapter lazily imports @elastic/elasticsearch, creates a shared Client, and reuses it across checks. When config is omitted, the default node is http://localhost:9200.

Existing client

Pass client as an existing Client. The adapter reuses that instance across checks.

Check metadata

Successful checks include cluster fields alongside any custom metadata hook output:
A yellow cluster yields degraded; a red cluster yields fail while still returning cluster metadata when the API call succeeds.

Wiring into createHealthKit

Treat the factory return value as adapter on a check (same as a hand-written { check() { ... } } object):
Combine with schedule on the check if you want cached readiness results instead of calling Elasticsearch on every probe (see Scheduling).