Skip to content
Latchkey

Elasticsearch "master_not_discovered_exception" in CI

The node came up but never formed a cluster with an elected master, so any request that needs the cluster state (creating an index, checking health) fails with master_not_discovered_exception. In CI this almost always means a single node started in multi-node discovery mode.

What this error means

API calls return "master_not_discovered_exception" with HTTP 503, and the cluster health call hangs or times out while the node waits for a master it will never find.

elasticsearch
{"error":{"root_cause":[{"type":"master_not_discovered_exception","reason":null}],
"type":"master_not_discovered_exception","reason":null},"status":503}

Common causes

A single node started without single-node discovery

Without discovery.type=single-node, the node expects to discover peers and hold a master election. With no peers it never elects a master.

initial_master_nodes was not set for a bootstrapped cluster

A multi-node config that omits cluster.initial_master_nodes cannot bootstrap voting, so no master is ever elected.

How to fix it

Use single-node discovery for a one-node test cluster

  1. Set discovery.type=single-node in the container environment.
  2. This bypasses master election entirely and the node becomes master of itself.
  3. Wait for a yellow or green status before running tests.
.github/workflows/ci.yml
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.13.4
    env:
      discovery.type: single-node

Bootstrap voting for an intentional multi-node cluster

If you really run more than one node, name the initial master-eligible nodes so the cluster can bootstrap.

.github/workflows/ci.yml
env:
  cluster.initial_master_nodes: es01,es02

How to prevent it

  • Set discovery.type=single-node for any single-node CI service.
  • Poll _cluster/health and wait for yellow before sending traffic.
  • Only run multi-node clusters when the test actually needs them.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →