Skip to content

Latest commit

 

History

History
34 lines (27 loc) · 720 Bytes

File metadata and controls

34 lines (27 loc) · 720 Bytes
endpoint ping
lang javascript
es_version 9.3
client @elastic/elasticsearch@9.3.0

Elasticsearch 9.3 ping endpoint (JavaScript example)

Use client.ping() to check whether the Elasticsearch server is reachable. Returns true if the server responds, false otherwise.

const alive = await client.ping();

if (alive) {
  console.log("Elasticsearch is available");
} else {
  console.log("Elasticsearch is not reachable");
}

Startup health check

Use ping at application startup to fail fast if Elasticsearch is unavailable:

const alive = await client.ping();
if (!alive) {
  console.error("Cannot connect to Elasticsearch — exiting");
  process.exit(1);
}