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.
{"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
- Set
discovery.type=single-nodein the container environment. - This bypasses master election entirely and the node becomes master of itself.
- Wait for a yellow or green status before running tests.
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.13.4
env:
discovery.type: single-nodeBootstrap 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.
env:
cluster.initial_master_nodes: es01,es02How to prevent it
- Set
discovery.type=single-nodefor any single-node CI service. - Poll
_cluster/healthand wait for yellow before sending traffic. - Only run multi-node clusters when the test actually needs them.