Master Election in Elasticsearch

Master Election in Elasticsearch

A complete, friendly guide to how a team of Elasticsearch servers agrees on exactly one leader, how that leader is replaced when it disappears, why a majority vote keeps the cluster safe, and how to design, operate, and troubleshoot the whole thing in production.

Picture a class of thirty students planning a school fair. Everyone has ideas, and everyone wants to change the plan: one wants the food stalls near the gate, another wants them at the back. If every student edited the plan on their own, there would soon be thirty different plans, and nobody would know which one was real. So the class does something sensible. It chooses one class president, using a fair vote, and the president keeps the single official notebook. Everyone can suggest changes, but only the president writes them down, and everyone else follows the notebook.

Now add a twist. What if the president is sick tomorrow? The class must choose a new president quickly, without any argument and without ever ending up with two presidents at the same time. That small story is the whole idea of master election in Elasticsearch. A group of servers must always agree on one leader, and when the leader disappears, they must agree on a replacement, safely and fast.

In this guide you will learn what master election is, why it needs a majority, how the vote actually works step by step, how the cluster notices a missing leader, and how to design and run a cluster that keeps its head in a crisis. You do not need any distributed systems background. Every new word is explained the first time it appears, and every big idea comes with an everyday comparison.

1What Is Master Election?

The shortest possible answer: master election is the process by which the master-eligible nodes of an Elasticsearch cluster choose exactly one of themselves to be the leader that manages cluster-wide decisions.

Let us build the definition slowly. Elasticsearch is a search and analytics engine. Companies use it to search products, explore application logs, count events, and draw charts. It usually runs as a cluster, which is a team of servers called nodes that share the work and the data. Data is stored in indices, which are like big labeled cabinets of documents, and each index is cut into pieces called shards so that many nodes can hold and search them together.

A team like this needs someone in charge of the things that affect the whole team: which indices exist, what fields they contain, which node holds which shard, and which nodes are currently part of the cluster. In Elasticsearch, that someone is the elected master node, often just called the master. At any moment, a healthy cluster has exactly one.

Master election is the voting procedure that picks that one node. It runs when a new cluster starts for the first time, and it runs again whenever the current master is lost, stops responding, or steps down. Only nodes that are allowed to lead, called master-eligible nodes, take part in the vote.

Everyday Analogy

Think of a ship with a crew of officers who are all qualified to be captain. At sea, only one of them holds the wheel at a time, because two captains giving different orders would crash the ship. If the captain falls ill, the officers meet, vote, and one takes the wheel. The election is not about who is the smartest. It is about making sure that there is always exactly one captain and that everyone knows who it is.

Three things that make an election safe

Elasticsearch’s election is built around three simple promises. First, at most one master at a time: the cluster must never have two leaders working in parallel. Second, majority rule: a node becomes master only when more than half of the voting members agree. Third, no lost decisions: a new master must know everything the old master had already decided, so that agreed changes are never forgotten.

1 master
Exactly one elected leader in a healthy cluster
Majority
More than half of the voters must agree to elect
A term
Each election gets a higher number, so old leaders are recognized as old
i
Name check

People say “master node,” “elected master,” “active master,” “cluster manager,” and “leader.” They point at the same role. “Master-eligible” describes a node that is allowed to be elected, while “elected master” describes the one that currently holds the job.

What master election is not

Master election does not decide where your documents live, and it does not sit in the path of every search or write. Searches and document writes flow directly between clients and the data nodes. The master handles the rules of the cluster, not the traffic. It is also different from the choice of a primary shard, which is the main copy of a slice of data. Chapter 16 explains this common confusion in detail.

Where you will meet it

You will meet master election when you start a brand-new cluster and must tell the nodes who the first voters are, when a node crashes and the cluster health flickers for a few seconds, when a network problem separates two groups of nodes, when you plan a rolling restart, and when you see log lines such as “master not discovered yet.” In each case, understanding the vote turns a mysterious message into a clear picture.

2Why It Exists: The Problem of Agreement

Getting many computers to agree is one of the hardest problems in computing. Master election is Elasticsearch’s answer: agree once on a leader, and let the leader make the rest of the decisions.

Imagine two nodes in the same cluster receive two requests at the same moment. One asks to create an index with a certain structure, and the other asks to create an index with the same name but a different structure. If both nodes act independently, the cluster now contains two versions of the truth. Searches will give different answers depending on which node they reach, and repairing the mess later can be painful or impossible.

One pen, one notebook

The simplest fix is to allow only one node to change the cluster’s structure. All requests that change the structure are sent to that node. It decides the order, applies each change, and tells everyone else the result. Because there is only one decision maker, conflicts cannot happen. This is the job of the elected master.

But a single leader creates a new problem. What if the leader dies? A cluster that depends on one fixed node is only as reliable as that node. So Elasticsearch lets several nodes be master-eligible, and it uses an election to choose a replacement automatically. The design goal is simple to say and difficult to achieve: there must always be at most one leader, and there must be a new one soon after the old one is gone.

Everyday Analogy

A group project works well when one person keeps the master document and everyone else sends changes to that person. It falls apart if two people each keep their own “master” copy and edit it privately. When the document keeper gets sick, the group must pick a new keeper and hand over the latest copy. Election is the group’s way of picking, and the handover rule makes sure that the newest copy wins.

The two hard truths of networks

Election is hard because computers and networks misbehave in two ways. First, messages can be lost or delayed. A node that does not answer might be dead, or it might be alive and simply slow, or the network cable between you and it might be cut. From the outside, these three cases look identical. Second, nodes can crash and restart at any time, forgetting whatever they kept only in memory. A good election method must stay correct under both problems.

The danger called split brain

The worst thing that can happen is split brain: a network problem cuts the cluster into two groups, and each group elects its own master. Now two leaders accept changes independently. When the network heals, the two histories cannot be merged, and some acknowledged changes must be thrown away. Older versions of Elasticsearch were exposed to this risk when administrators set the voting rules incorrectly. Modern versions prevent it by design, using majority voting. Chapter 8 tells the full story.

An illustrative story

ChatWave, an imaginary messaging startup

ChatWave runs message search on a cluster of nine nodes across two rooms of one data center. In the early days, the team let any node become master and never thought about voting rules. One night, a network switch between the rooms fails. Each room continues to work, and each room’s nodes elect a leader. For an hour, two masters create and delete indices independently. When the switch is repaired, the team finds two different lists of indices and has to restore from backups. This story is invented to make the danger clear. The same failure in a modern cluster cannot happen, because only the room with a majority of voters can elect a master, and the other room simply pauses until it can rejoin.

A short history

Older Elasticsearch versions, up to the 6.x line, used a homegrown method called Zen Discovery. It worked, but it demanded that administrators set a number by hand, the minimum number of master nodes, and mistakes in that number were a common cause of data problems. Version 7.0 introduced a new cluster coordination system, designed with a formal model and inspired by well-known agreement algorithms such as Raft. It manages the voting rules automatically, made elections faster and safer, and removed the old manual setting. This guide describes that modern system.

!
Do not confuse old advice with new

Many older articles and forum posts talk about setting the minimum number of master nodes. That advice applies to old versions only. In modern versions, the cluster maintains its own voting rules, and setting that old option is not needed and not supported.

3The Building Blocks You Need to Know First

To follow the rest of this guide you need eight simple ideas: node, cluster, role, cluster state, quorum, vote, term, and the three election states.

Node

One running copy of Elasticsearch

A node is one server process. Think of nodes as the branches of a library chain that share one catalog.

Cluster

A team of nodes

Nodes with the same cluster identity that can reach each other form a cluster. They act like one system for the outside world.

Role

The job a node may do

Each node has roles such as master, data, or ingest. The master role means the node is allowed to lead and to vote.

Cluster state

The shared notebook

A structure that lists all indices, settings, mappings, nodes, and shard locations. Every node holds a copy, and only the master changes it.

Quorum

A majority of the voters

More than half of the voting members. A decision counts only when a quorum agrees, which makes conflicting decisions impossible.

Vote

A node’s yes for a candidate

A node grants at most one vote per election round. In Elasticsearch, a vote is sent as a message called a join.

Term

The number of the election round

Every election happens in a numbered term. Higher terms beat lower ones, like school years that always move forward.

States

Candidate, leader, follower

Every master-eligible node is at any time a candidate looking for a leader, the leader itself, or a follower of the leader.

Consensus in plain words

The word consensus means that a group of computers agrees on a value, even when some of them fail and messages go missing. Master election is a consensus problem: the value to agree on is “who is the leader right now.” Publishing a change to the cluster state is another consensus problem: the value to agree on is “what is the new state.” Elasticsearch solves both with the same idea, that a decision is valid only when a majority accepts it.

Why majorities work

Any two majorities of the same group must overlap in at least one member. If five nodes vote, any group of three and any other group of three share at least one node. That shared member cannot vote for two different leaders in the same round, so two competing leaders can never both win. This overlap property is the mathematical heart of safe elections, and it explains why odd numbers such as three or five master-eligible nodes are recommended.

Everyday Analogy

Picture a jury of five people. A verdict needs at least three. Suppose two different groups try to announce two different verdicts. Each would need three people, but there are only five, so at least one juror would have to sign both. Since a juror signs only one verdict, the two groups cannot both succeed. Majority voting uses exactly this trick to stop two leaders from existing at once.

A cluster in one picture

The diagram shows a small cluster. Three master-eligible nodes take part in elections, and one of them is currently the elected master. Data nodes hold the shards. Clients reach the cluster through a load balancer or an API gateway that spreads requests over the nodes.

flowchart TD
    A["Client application"] --> B["Load balancer or API gateway"]
    B --> D1["Data node 1"]
    B --> D2["Data node 2"]
    B --> D3["Data node 3"]
    M1["Master-eligible node 1: elected master"] --- M2["Master-eligible node 2: follower"]
    M2 --- M3["Master-eligible node 3: follower"]
    M1 --- M3
    M1 -.->|Publishes cluster state| D1
    M1 -.->|Publishes cluster state| D2
    M1 -.->|Publishes cluster state| D3
Figure 1: Clients talk to data nodes. The three master-eligible nodes elect one leader, which publishes the cluster state to every node.

Look closely at Figure 1. Client requests do not go through the master. The dotted lines show that the master sends the cluster state, the shared notebook, to all nodes. This split between the control path and the data path is one of the most important ideas in Elasticsearch operations.

i
Good to know

The word “cluster state” will come back many times. Whenever you read “the master publishes” or “the nodes apply,” it means that the master sends the newest notebook to all nodes, and every node updates its own copy.

4Node Roles and Who Can Become Master

Not every node is allowed to lead. Roles decide who can vote, who can be elected, and who only does data work.

Every Elasticsearch node has a list of roles, set in its configuration. The roles tell the cluster what the node is allowed to do. Some roles are about data, such as holding shards or processing incoming documents. One role, master, is about leadership. A node with the master role is a master-eligible node: it takes part in elections and may be chosen as the leader.

The main roles for elections

Role setupVotes in elections?Can be elected?Typical use
Master only (dedicated master)YesYesProduction clusters that want stable, lightweight leaders
Master together with data and other rolesYesYesSmall clusters and development setups
Master together with voting-onlyYesNoA tiebreaker node that helps form a majority but never leads
Data only, no master roleNoNoNodes that store and search shards
No roles at all (coordinating only)NoNoNodes that route requests and merge results

Dedicated master nodes

A dedicated master node has only the master role. It holds no shards and does no searching or indexing. Its whole job is to keep the cluster state and take part in elections. Because it is not busy with heavy work, it responds quickly and is less likely to be pushed into long pauses. Large production clusters almost always use dedicated masters, often three of them. Small clusters may skip them and let data nodes also be master-eligible, at the cost of mixing heavy work with leadership work.

Voting-only nodes

A voting-only node is a master-eligible node that has been given an extra role called voting_only. It votes like any other master-eligible node, but it can never become the leader. This is useful as a cheap tiebreaker. If you have two rooms with one master-eligible node each, a third small voting-only node in a third location lets the cluster keep a majority when one room fails, without needing a full-sized leader there.

Everyday Analogy

In a school council, some members are qualified to run for president and can also vote. A voting-only member is like a respected elder who holds a vote in every election but has decided never to run. Their vote helps break ties, and their presence costs the school very little.

Data nodes and coordinating nodes

A data node stores shards and runs searches and indexing on them. A coordinating node has no special roles and simply receives client requests, sends them to the right shards, and merges the answers. Neither of them votes or leads. They follow the cluster state that the elected master publishes. In a well-designed cluster, these roles are separated so that heavy queries cannot disturb leadership.

flowchart LR
    subgraph Voters["Master-eligible nodes: can vote"]
        A["Master-eligible node A: may lead"]
        B["Master-eligible node B: may lead"]
        C["Voting-only node C: votes, never leads"]
    end
    subgraph Workers["Nodes without the master role: no vote"]
        D["Data node"]
        E["Data node"]
        F["Coordinating node"]
    end
    A -.-> D
    A -.-> E
    A -.-> F
Figure 2: Only nodes in the left group vote. Nodes in the right group follow the cluster state without taking part in elections.

Setting roles

Roles are listed in the node’s configuration file using the node.roles setting. If the setting is missing, a node receives a default set of many roles, including master and data. This default is convenient for learning, but for production you should choose roles on purpose, because a node that quietly holds the master role can be elected even if you never planned it.

!
More voters is not better

It is tempting to make every node master-eligible “for safety.” In a large cluster this backfires. Every extra voter makes elections and cluster state updates slower, because more nodes must respond. Keep the number of master-eligible nodes small and odd, usually three, sometimes five.

5What the Master Actually Does, and What It Does Not

The master is the cluster’s manager, not its worker. Knowing the exact scope of its job helps you size it, protect it, and predict what breaks when it is missing.

The elected master is responsible for cluster-wide decisions. These are the decisions that must be made once and shared by everyone. Because it is the only node that changes the cluster state, it sees every structural change before anyone else does.

The master’s duties

  • Tracking membership. It knows which nodes are part of the cluster, adds nodes that join, and removes nodes that stop responding.
  • Creating and deleting indices. When a client asks for a new index, the master decides its settings and records it in the cluster state.
  • Managing mappings. A mapping describes the fields of an index and their types. When new fields must be added, the master approves and records the change.
  • Deciding shard allocation. It decides which node holds which shard copy, moves shards to balance load, and promotes a replica to primary when a primary is lost.
  • Handling settings and templates. Changes to cluster settings, index settings, and templates flow through it.
  • Running some management jobs. Several scheduled housekeeping features, such as index lifecycle management, are driven from the elected master.

What the master does not do

The master does not receive your search requests, and it does not receive your document writes. A write goes from the client to a node, then to the node holding the primary shard, and then to the replicas. A search goes to the nodes holding the relevant shards. The master is not on that path. This is why a cluster can keep answering searches for existing data even in the short moment when there is no master, though it cannot change its structure until a new master appears.

TaskGoes through the master?Why
Create or delete an indexYesIt changes the cluster state, which only the master can change
Add a new field through a mapping changeYesMappings live in the cluster state
Move a shard to another nodeYesThe master owns the shard routing table
Detect that a node has leftYesThe master checks on followers and updates membership
Send a search requestNoClients talk to nodes that hold or coordinate shards
Index a normal document into an existing indexNo, unless a mapping change is neededThe write goes to the primary shard directly
Read a document by its idNoA data node answers from the shard
Everyday Analogy

An airport has a control tower and many airplanes. The tower decides which runway each plane uses and who lands when, but it never carries a passenger. If the tower loses power for a moment, planes already in the air keep flying, though no new schedule changes can be made until the tower is back. The master is the tower, and data nodes are the planes.

A busy master can slow the whole cluster

Although the master is not on the data path, every structural change waits in a queue at the master. If the master is overloaded, creating an index or applying a mapping may take a long time, and shard recovery after a failure may be delayed. Clusters with thousands of indices or hundreds of thousands of shards give the master a heavy workload. Later chapters show how to spot and prevent that.

A good mental model

Think of the cluster as having two parts. The control plane decides how the cluster is organized, and the master lives there. The data plane stores and searches the data, and data nodes live there. A healthy design keeps the control plane light and stable, so that decisions are quick, and lets the data plane grow with your traffic.

i
Practical rule

If a change touches the structure of the cluster, the master is involved. If it touches the contents of an existing document, the master is not. When the cluster feels slow only for structural actions like creating indices, look at the master first.

6The Cluster State: The Notebook the Election Protects

Everything the master decides ends up in one structure. Understanding it explains why elections must be careful and why a huge cluster state slows everything down.

The cluster state is a compact record of how the cluster is organized right now. It is the shared notebook of the whole team. Every node holds a recent copy, and the elected master is the only one allowed to write in it.

What is inside

Membership

Which nodes are in

The list of nodes in the cluster, with their identifiers, addresses, and roles, and which one is the elected master.

Metadata

Indices, settings, and mappings

The definition of every index, its settings, its field mappings, plus templates and cluster-wide settings.

Routing

Where every shard lives

The routing table says which node holds each primary and replica shard, and which shard copies are unassigned.

Blocks

Restrictions in force

Blocks such as read-only indices or the no-master block that protects the cluster during a leadership gap.

Notice what is not in the cluster state: your documents. The state holds the structure, not the contents. Even so, it can grow large in clusters with many indices, many fields, or many shards, and its size is a key factor in how fast the master can work.

Versions and terms on every state

Each published cluster state carries two numbers: the term of the leader that produced it, and a version that increases with every change. Together they tell any node which of two states is newer. A state from a higher term is always newer, and within the same term, a higher version is newer. These two numbers play a central role in elections, because a voter compares them before deciding whether a candidate is up to date.

Everyday Analogy

Consider a shared class notebook with a stamp on every page: the school year and the page number. If two notebooks disagree, the one with the later school year is newer, and within the same year, the one with the higher page number is newer. A new class president always takes over the newest notebook, not an older copy someone kept in a drawer.

Stored on disk for safety

Master-eligible nodes save the current term and the latest accepted cluster state on their own disks before they acknowledge a change. Because of this, a restarted master-eligible node remembers what it agreed to. Without this memory, a node could forget that it had already voted, and might vote twice in the same term, which would break the safety of the election. This is why the data directory of a master-eligible node must never be wiped casually, and why a fast, reliable disk matters even for a dedicated master that holds no shards.

Full states and differences

When the master publishes a change, it does not always send the whole notebook. If a node already has the previous version, the master sends only the difference, which is small and quick. If a node is new, or has fallen too far behind, the master sends the full state. Big clusters benefit a lot from this saving, but a very large state still costs time whenever a full copy has to travel.

Why size matters

Every structural change means computing a new state, sending it to all nodes, waiting for acknowledgments, and applying it. The larger the state, the longer each step takes. Common causes of a bloated state include huge numbers of tiny indices, indices with thousands of fields, and unbounded creation of new fields from unpredictable data. A clean design keeps the state small, which keeps the master fast and elections calm.

!
Mapping explosion

If an application uses data values as field names, every new value adds a field to the mapping, and the master must publish that growth to every node. This pattern, known as mapping explosion, is one of the most common ways a healthy cluster slowly turns into a slow one.

7Quorum and the Voting Configuration

A quorum is the number of votes that must agree before a decision counts. Elasticsearch keeps track of who is allowed to vote and adjusts that list automatically.

The set of master-eligible nodes whose votes count is called the voting configuration. A quorum is a majority of that set: more than half of its members. For a voting configuration of three nodes, a quorum is two. For five, it is three. The formula is simply half the number of voters, rounded down, plus one.

How many failures can you survive?

Master-eligible nodes in the voting setQuorum neededFailures toleratedComment
110Simple and fine for development, no fault tolerance
220No better than one node, and Elasticsearch avoids relying on both
321The standard production choice
431No better than three, so an even number wastes a node
532Good for very important clusters or three-zone layouts
743Rarely needed, and it slows coordination a little

The pattern is that adding a node to make an even number gives no extra protection, because the quorum grows along with the group. That is why guides insist on odd numbers. Elasticsearch enforces this automatically: if you have an even number of master-eligible nodes, it leaves one of them out of the voting configuration, so the effective number of voters stays odd.

Everyday Analogy

Picture a committee with four members that needs three votes to pass a decision. Two of them can never decide alone, and losing two members stops all decisions. A committee of three needs two votes and also survives losing one member. The fourth member adds cost and no resilience. The same arithmetic applies to master-eligible nodes.

Automatic adjustment

The voting configuration is not fixed. When master-eligible nodes join or leave, the elected master changes the configuration for you, as long as the change is safe. This adjustment is what removed the need for the old manual “minimum master nodes” setting. You can grow a cluster from three to five master-eligible nodes, and the voting set follows. You can also shrink it, as long as you follow the safety rule below.

The safety rule for removing nodes

The rule is easy to remember: never stop half or more of the voting nodes at the same time. If you stop fewer than half, the remaining nodes still hold a quorum, and the master can update the voting configuration to match. Wait for that adjustment to finish before stopping the next node. If you must remove half or more of the master-eligible nodes, use the voting configuration exclusions feature, which tells the cluster to move the vote away from those nodes first, so that shutting them down does not cost you the quorum.

1

Count your voters

Find out how many master-eligible nodes are in the voting configuration, not just how many exist.

2

Decide how many to remove

If the number to remove is less than half, you can stop them one by one. Otherwise plan an exclusion.

3

Stop one node, then wait

After each stop, wait until the cluster has adjusted its voting configuration and is healthy before the next stop.

4

Use exclusions for big cuts

Ask the cluster to exclude the nodes you plan to retire, wait until they leave the voting configuration, then shut them down.

5

Clean up the exclusion list

After the nodes are gone, clear the exclusion list so it does not block future nodes with the same names.

i
A calm rule of thumb

Change master-eligible nodes slowly and one at a time. A cluster that loses its quorum stops accepting structural changes, so haste can turn a planned task into an outage.

8Split Brain: The Old Danger and How It Is Prevented

Split brain is the classic disaster of leader-based systems. Modern Elasticsearch prevents it by making it mathematically impossible for two leaders to win.

Suppose a cluster of five nodes is running happily, and a network fault cuts it into two groups: three nodes on one side and two on the other. Each side can still talk internally, but not across the cut. From the point of view of each group, the other side has vanished.

What would go wrong without majority voting

If the two-node group decided that it must elect its own master because the old one is out of reach, it would do so. Both groups would then accept changes independently. After the network is repaired, the two histories conflict: two sets of indices, two shard layouts, and possibly two different versions of the same document. Data written to one side must be discarded. That outcome is called split brain, and it is a data loss event.

How the quorum rule stops it

With majority voting, only the group that holds a majority of the voting configuration can elect or keep a master. In our example, the group of three has a quorum of three out of five, so it continues normally. The group of two has only two out of five, which is not a majority, so it cannot elect a master. It stops changing the cluster and waits. When the network heals, the two nodes rejoin the larger group and catch up. No decision was made in two places, so nothing needs to be thrown away.

flowchart TD
    subgraph Before["Before the network fault: 5 voters, one cluster"]
        A1["Node 1"] --- A2["Node 2"] --- A3["Node 3"] --- A4["Node 4"] --- A5["Node 5"]
    end
    Before --> Cut["Network fault splits the cluster"]
    Cut --> Side1["Side with 3 nodes: has a majority, elects or keeps a master"]
    Cut --> Side2["Side with 2 nodes: no majority, cannot elect a master, waits"]
    Side2 --> Heal["Network heals: the 2 nodes rejoin and catch up"]
Figure 3: Majority voting means that at most one side of a network split can have a master. The minority side pauses instead of making conflicting decisions.
Everyday Analogy

Two groups of hikers get separated in fog. The group with three of the five original members says, “We are the majority and still have the map, so we will continue the plan.” The group with two says, “We are the minority, so we will stay put and wait until we can reconnect.” Nobody walks off in a different direction, and when the fog lifts, the plan is still consistent.

Old and new compared

AspectOld system (Zen Discovery, before 7.0)Modern system (7.0 and later)
Quorum settingSet by hand as a minimum number of master nodesManaged automatically as the voting configuration
Risk if misconfiguredSplit brain and data loss were possibleMisconfiguration cannot cause two masters
Changing the number of master-eligible nodesRequired updating the setting on all nodes at the right momentThe cluster adjusts itself, with simple safety rules for removal
Election speedSlower, with long timeoutsFast, using short randomized delays
Design methodGrown organicallyBuilt on a formal model inspired by proven agreement algorithms
Bootstrapping a new clusterNodes discovered each other by pingingExplicit list of initial voters in a new cluster

What the minority side experiences

Nodes on the minority side cannot see a master, so they apply a protective block. By default, this block rejects write operations, while reads continue against the last known cluster state, which may be a little stale. If you prefer the strictest behavior, the cluster.no_master_block setting can be changed to reject all operations. Clients that are connected to the minority side will see errors such as “master not discovered” or “blocked by no master,” until the cluster heals or the client reaches the majority side.

Why three zones matter

The majority rule has an implication for where you place master-eligible nodes. If all three are in one data center room, a failure of that room takes out all voters. If they are spread over three separate zones, the loss of any one zone leaves two voters, which is still a majority. This is why many production designs use three zones, or two zones plus a tiebreaker in a third. Chapter 18 shows those designs.

!
Two rooms are not enough

With master-eligible nodes in only two rooms, one room always holds fewer than or exactly half of the voters. If the room with the majority fails, the survivors cannot form a quorum. A small voting-only node in a third location fixes this at a low cost.

9Forming a Cluster: Discovery and Bootstrapping

Before any election can happen, nodes must find each other. And a brand-new cluster needs a one-time founding step to decide who the first voters are.

Discovery: finding your peers

Discovery is the process by which a node finds other nodes that might be part of its cluster. A node cannot search the whole network, so you give it a list of addresses to try, called seed hosts, in the discovery.seed_hosts setting. The list does not need to include every node, only enough well-known ones. The node contacts these addresses, and they tell it about the other nodes they know. This chain of introductions spreads knowledge of the whole group.

In cloud environments, you can use a seed provider instead of a fixed list. A provider asks the cloud platform or a file for the current addresses, which is convenient when machines come and go. Containers and Kubernetes setups often use a service name that resolves to the current members.

Everyday Analogy

Imagine arriving in a new city and having only the phone numbers of two friends. You call them, and each tells you the names of other people they know, and so on, until you have met the whole group. Seed hosts are those first phone numbers, and the chain of introductions is discovery.

Bootstrapping: the founding meeting

A brand-new cluster has a special problem. There is no existing voting configuration, so nobody knows how many votes are needed. Elasticsearch solves this with a one-time bootstrap. You provide the setting cluster.initial_master_nodes, a list of the names of the master-eligible nodes that will form the first voting configuration. Each of these nodes waits until it has found a majority of the listed nodes, and then the first election can take place.

flowchart TD
    A["Master-eligible nodes start for the first time"] --> B["Each node probes its seed hosts"]
    B --> C["Nodes find each other and compare the initial master node list"]
    C --> D{"Found a majority of the listed initial nodes?"}
    D -->|No| E["Keep probing and log that the master is not discovered yet"]
    E --> B
    D -->|Yes| F["First election runs and one node becomes master"]
    F --> G["Voting configuration is stored in the cluster state"]
    G --> H["The initial master nodes setting is no longer needed"]
Figure 4: Bootstrapping happens once, when a cluster is created. After the first election, the cluster manages its own voting configuration.

Rules of bootstrapping

  • Use it only for a brand-new cluster. After the cluster has formed, the initial master nodes setting has no purpose and should be removed from the configuration.
  • Never use it on a node that joins an existing cluster. A new node that is told to bootstrap may create its own separate cluster instead of joining the real one.
  • List the same nodes everywhere. Every master-eligible node in the first group should have an identical list of names, using each node’s configured node name.
  • Do not include non-master nodes. The list names only the founding voters.
  • Do not bootstrap two clusters with the same seed hosts. This confuses which nodes belong together.
Everyday Analogy

A new club needs a founding meeting. The founders sign a list saying, “These five people are the founding members, and a decision needs three of us.” Once the club exists, new members simply apply, and the founding list is put away in a drawer. If someone shows up at a running club with a new founding list, they would start a second club by accident, which is exactly the mistake to avoid.

What happens on a laptop

If you start Elasticsearch on a single machine for learning, without special network settings, nodes on that machine can find each other and form a cluster automatically. This convenience applies only in development mode, when the node listens on the local machine. In production mode, where the node listens on a real network address, Elasticsearch runs strict startup checks and refuses to start unless discovery is configured with seed hosts, a provider, or the initial master list. This prevents accidental clusters that never form.

The single-node case

A cluster of one node is a valid cluster, and it elects itself. For this case, Elasticsearch offers a single-node discovery mode that skips the search for peers. It is useful for development and tests. It is not a way to run a fault-tolerant service, since the loss of that one node loses the cluster.

Cluster identity

Once a cluster is created, it receives a unique identifier that is stored in its cluster state and on the disks of its nodes. A node that carries the identity of one cluster refuses to join a different cluster, even if the names look the same. This safety catch prevents data from two unrelated clusters from being mixed, and it explains an error you may meet if a node was accidentally bootstrapped on its own.

i
Log messages to know

While a cluster forms, nodes log lines like “master not discovered yet, this node has not previously joined a bootstrapped cluster.” Read the rest of the message. It usually lists which nodes the node has found and which it still needs, and that points straight to the cause.

10The Election, Step by Step

Here is the heart of the topic: how a group of candidates turns into one leader in a fraction of a second, without any central coordinator.

An election begins when a master-eligible node finds itself without a leader. This is true when a node starts up, when it loses contact with the leader, or when the leader tells the world that it is stepping down. The node becomes a candidate and goes through the following steps.

1

Discover the peers

The candidate probes its seed hosts and known nodes to learn which master-eligible nodes are reachable and what they know.

2

Wait a random moment

To avoid everybody starting at once, each candidate waits a short, random delay. The delay grows a little after each failed attempt.

3

Ask if a vote is likely

In a pre-voting round, the candidate asks the others whether they would vote for it. Nodes that are happy with their current leader say no. If no quorum would say yes, the candidate does not start an election, so it cannot disturb a healthy cluster.

4

Start a new term

If a quorum looks willing, the candidate picks a term number higher than any it has seen and sends a request for votes to all master-eligible nodes it knows.

5

Voters check and reply

Each node votes for at most one candidate per term. It refuses to vote for a candidate whose cluster state is older than what the voter has already accepted, because that candidate might not know about some agreed changes.

6

Count the votes

When the candidate has received votes from a quorum of the voting configuration, including its own, it wins and becomes the leader for this term.

7

Announce with a cluster state

The new leader publishes a cluster state that names it as master. When that publication is accepted by a quorum, the election is complete, and other nodes become followers.

sequenceDiagram
    participant A as Candidate A
    participant B as Node B
    participant C as Node C
    A->>B: Pre-vote: would you vote for me?
    A->>C: Pre-vote: would you vote for me?
    B-->>A: Yes
    C-->>A: Yes
    A->>A: Choose a higher term
    A->>B: Request a vote for the new term
    A->>C: Request a vote for the new term
    B-->>A: Vote granted
    C-->>A: Vote granted
    A->>A: Quorum reached, become leader
    A->>B: Publish cluster state naming A as master
    A->>C: Publish cluster state naming A as master
    B-->>A: Accepted
    C-->>A: Accepted
    A->>B: Commit
    A->>C: Commit
Figure 5: A simplified election with three master-eligible nodes. Pre-voting first checks that an election is likely to succeed, then votes are collected, and finally the leader announces itself through a published cluster state.
Everyday Analogy

Think of a class electing a new president after the old one moves away. A student first asks around quietly, “Would you vote for me if I ran?” If most say yes, the student announces a formal election for the new school term. Each classmate can raise a hand for only one candidate. The student with more than half of the hands wins, and the teacher writes the result in the class notebook. If the quiet poll shows no support, the student does not run, and the class avoids a pointless, noisy vote.

Why pre-voting matters

Without pre-voting, a node that was briefly cut off from the network would return with a higher term number and force the healthy leader to step down, even though nothing was wrong with the cluster. That disruption is like a student who was absent for a week coming back and demanding a new election. Pre-voting stops it: nodes that are content with their leader answer no, so the returning node cannot gather a quorum and simply rejoins as a follower.

The up-to-date rule

The check in step five protects agreed decisions. A voter remembers the newest cluster state it has accepted, identified by term and version. It will not vote for a candidate whose newest state is older. Because a change is committed only after a quorum has accepted it, and any two quorums overlap, at least one voter in the winning quorum holds every committed change. Therefore, a winning candidate has always seen everything that was committed, and no agreed change is ever forgotten.

When two candidates compete

Sometimes two nodes start at almost the same time, and each gets some votes but neither gets a majority. This is called a split vote. Nothing bad happens: both attempts simply fail, and the candidates wait different random delays before trying again. Randomness makes it very unlikely that they collide twice in a row. Typically, one of them wins within a fraction of a second.

i
Terms only grow

The term number never goes down. Every election uses a term higher than the last. If an old leader from an earlier term ever appears again, everyone can tell from its lower term that it is out of date, and it steps down.

11Election States and Terms

Every master-eligible node is always in one of three states. Watching how nodes move between them makes leadership changes easy to understand.

A master-eligible node is at any moment a candidate, a leader, or a follower. These three states form a simple cycle, and every transition has a clear cause.

stateDiagram-v2
    [*] --> Candidate
    Candidate --> Leader: Wins an election with a quorum
    Candidate --> Follower: Accepts a leader that already exists
    Follower --> Candidate: Leader checks fail
    Leader --> Candidate: Loses quorum or sees a higher term
    Follower --> Follower: Applies published cluster states
Figure 6: The three states of a master-eligible node. A node at rest is a follower or leader, and it becomes a candidate only when leadership is in doubt.
Candidate

Looking for a leader

A candidate probes for peers, waits its random delay, and may start an election. Every node begins its life as a candidate.

Leader

The elected master

The leader publishes cluster states, checks on followers, and processes all structural changes. It steps down if it cannot keep a quorum.

Follower

Loyal to the current leader

A follower accepts published states, answers the leader’s health checks, and checks that the leader is still alive.

What a term really means

A term is a numbered period of leadership. When an election succeeds, the winner leads for that term. If the leader is lost and a new election starts, the number goes up by at least one. Terms make it possible to compare claims: when two nodes both think they are leader, the one with the higher term is right, and the other must step down. Terms are stored on disk together with the cluster state so that they survive restarts.

Everyday Analogy

School years work like terms. Each year has a president, and each new year has a bigger number. If somebody claims to still be president from last year, everyone checks the calendar and sees that the year has moved on. Terms are the calendar of the cluster.

The rules that keep the states safe

  • One vote per term. A node grants at most one vote in any term, and it remembers this even after a restart, because the term and its vote are saved on disk.
  • Higher term wins. A node that receives any message with a higher term immediately updates its own term and gives up any leadership claim.
  • Only a quorum makes a leader. A candidate does not become leader on the strength of a few votes, and it does not become leader by declaring itself so.
  • Leaders must keep proving themselves. A leader that cannot get a quorum to accept its published states steps down.

Leader stability in practice

In a healthy cluster, the leader stays the same for days or weeks, and the term number hardly changes. If you see the term increase often, it means that leadership is unstable, and something in the environment is causing nodes to lose contact: long pauses, a flaky network, overloaded machines, or too tight timeouts. A stable term number is a quiet sign of a healthy cluster.

Nodes that are not candidates

Data nodes and other nodes without the master role never go through these states. They simply find the elected master, join it, and follow its cluster states. If the master changes, they detect the change and connect to the new one. They do not vote, and they cannot become leaders.

i
Good to know

You can look at the term and the voting configuration in the cluster state metadata. Seeing which nodes are in the last committed configuration is a quick check when you wonder whether a particular node’s vote really counts.

12Election Timing: Randomness on Purpose

Elections rely on small random delays to avoid collisions. A handful of settings control those delays, and the defaults are usually right.

If every master-eligible node started an election the instant it lost the leader, all of them would collide, votes would be split, and nobody would win. Elasticsearch solves this with randomized waiting. Each candidate waits for a random time before it tries, so one of them almost always goes first and collects the votes before the others even start.

Setting

cluster.election.initial_timeout

The upper limit of the first random wait. The default is 100 milliseconds. Each candidate picks a random delay between zero and this limit.

Setting

cluster.election.back_off_time

How much the upper limit grows after each failed attempt. The default is 100 milliseconds. Repeated failures lead to longer, more spread-out waits.

Setting

cluster.election.max_timeout

The ceiling for the wait, so the delays do not grow forever. The default is 10 seconds.

Setting

cluster.election.duration

How long a candidate waits for votes before it gives up on that attempt. The default is 500 milliseconds.

Everyday Analogy

Picture a room of polite people who all want to speak after a long silence. If everybody starts talking at once, nobody is heard. A simple trick is for each person to count to a random number in their head before speaking. Whoever has the smallest count speaks first, and the others hear them and stay quiet. If two people happen to start together, both stop, count to bigger random numbers, and try again. That is exactly how election delays work.

How the back-off works

The first attempt uses a wait between zero and the initial timeout. If the attempt fails, the upper limit grows by the back-off time. After the second failure, it grows again, and so on, until it reaches the maximum. This growing range means that when the cluster is having real trouble, for example because many nodes are competing or the network is slow, candidates spread out further and further apart, which makes a clean win more likely.

When to change them

Almost never. The defaults were chosen for typical networks. If your nodes are on a network with high latency, for example spread across distant places, votes take longer to travel, and the election duration may need to be raised so that candidates do not give up before the replies arrive. Lowering the values too much can cause repeated collisions. Raising them too much makes recovery slower than necessary. Treat any change as an experiment to be tested in a non-production cluster first.

Elections are quick when the cluster is healthy

Because the delays are short and the vote is a single round of messages, an election in a healthy cluster with a good network takes a fraction of a second. Most of the total time of a failover is not the election itself, but the time to notice that the old leader is gone, which is the topic of Chapter 14.

!
Do not tune to hide a problem

If elections keep failing or repeating, the cause is usually not the timing settings. Look for unstable networks, overloaded or paused nodes, wrong seed hosts, or a cluster that does not have a quorum. Changing timeouts can hide the symptom while the cause remains.

13Publishing Cluster State: The Two-Phase Commit

After the election, the leader’s daily work is to publish changes. Each change is announced, confirmed by a majority, and only then made official.

Every structural change, whether it is a new index, a moved shard, or a new node, becomes a new cluster state. The leader must be sure that the change is safely recorded by a majority before anyone treats it as real. It uses a two-step procedure known as a two-phase commit. In the first phase, the change is proposed and accepted. In the second phase, it is committed and applied.

1

A request arrives

A client asks for a structural change, or the master itself decides on one, such as removing a lost node.

2

The master computes a new state

It takes the current state, applies the change, and produces a new state with a higher version.

3

The state is published to all nodes

The master sends the new state, usually as a small difference, to every node in the cluster.

4

Nodes accept and save it

Each master-eligible node checks the term and version, writes the accepted state to disk, and replies that it has accepted it.

5

A quorum accepts, so the master commits

When a majority of the voting configuration has accepted, the master sends a commit message. The change is now agreed and cannot be lost.

6

Nodes apply the state

Each node applies the committed state: it creates the shard, updates its view of the mappings, or starts talking to the new node.

7

The master waits for the applications

The master waits for the nodes to report that they applied the state, up to a time limit, and then answers the client that made the request.

sequenceDiagram
    participant Cl as Client
    participant M as Elected master
    participant N1 as Node 1
    participant N2 as Node 2
    Cl->>M: Create an index
    M->>M: Compute the new cluster state
    M->>N1: Publish new state
    M->>N2: Publish new state
    N1-->>M: Accepted and saved to disk
    N2-->>M: Accepted and saved to disk
    M->>N1: Commit
    M->>N2: Commit
    N1-->>M: Applied
    N2-->>M: Applied
    M-->>Cl: Index created
Figure 7: A cluster state change is proposed, accepted by a majority, committed, and finally applied. Only then does the client hear that its request succeeded.
Everyday Analogy

Think of a school principal announcing a change in the timetable. First, the principal sends a note to all class teachers saying, “I propose this change.” Teachers write it in their planners in pencil and send back a slip saying, “Received.” When more than half of the slips are back, the principal sends a second note saying, “It is official now.” Teachers then rewrite the timetable in ink. Nobody acts on the change in the first step, so if the principal never gets enough slips, the change is simply dropped.

Why two phases

The first phase lets the leader find out whether a majority can store the change. If it cannot reach a majority, it does not commit, and no node ever treats the change as final. This protects against the case where the leader crashes halfway through: a change that was never committed can be forgotten, while a change that was committed is guaranteed to exist on a majority and will be found by the next leader.

The queue of changes

The master handles changes one at a time, in order of priority. Urgent tasks, such as removing a lost node or promoting a replica, come before routine ones, such as cleaning up. Tasks of the same kind are batched together when possible to save work. The list of waiting tasks can be inspected with the pending tasks operation. A long queue is a sign that the master is overloaded or that its changes are slow to be accepted.

Timeouts of publication

A publication must finish within the cluster.publish.timeout setting, which is 30 seconds by default. If a majority does not commit in that time, the master concludes that it cannot lead and steps down, which triggers a new election. A separate setting, cluster.publish.info_timeout, controls after how long an informational log line is written to warn that a publication is taking suspiciously long. Nodes that are slow to apply a committed state are watched by a lag detector, and a node that does not catch up within the follower lag timeout, by default 90 seconds, is removed from the cluster so that it cannot hold everything back.

A failed publication

If the master cannot get a quorum to accept a state, for example because of a network split, it does not commit and it steps down. Followers that never received a commit keep the older, committed state. This is how the cluster avoids exposing half-finished changes, and why the newest committed state is always safe to rely on.

i
Keep an eye on publication time

The time from computing a state to the last node applying it is a key health number. If it rises over weeks, something is growing: the cluster state itself, the number of nodes, or the load on a slow node.

14Fault Detection: How the Cluster Notices a Missing Master

An election begins only when someone notices that the leader is gone. Regular health checks in both directions make that happen.

Once a cluster is formed, its nodes keep checking on each other with a steady heartbeat. There are two kinds of check, and they run in opposite directions.

Leader check

Followers ask the leader

Every follower regularly asks the elected master, “Are you still there and still the leader?” If the answer fails repeatedly, the follower stops trusting the leader and becomes a candidate.

Follower check

The leader asks the followers

The elected master regularly asks every node in the cluster, “Are you still there?” If a node fails to answer after several tries, the master removes it from the cluster.

The settings behind the checks

Setting familyDefaultMeaning
Interval of leader and follower checks1 secondHow often each check is sent
Timeout of leader and follower checks10 secondsHow long to wait for a reply to one check
Retry count of leader and follower checks3How many failed checks in a row are needed before giving up on the other node

These are controlled by the settings cluster.fault_detection.leader_check.* and cluster.fault_detection.follower_check.*, each with interval, timeout, and retry count. With the defaults, a node that stops answering entirely is declared failed after about half a minute in the worst case.

flowchart TD
    A["Follower sends a leader check every second"] --> B{"Reply received in time?"}
    B -->|Yes| A
    B -->|No| C["Count a failure"]
    C --> D{"Three failures in a row?"}
    D -->|No| A
    D -->|Yes| E["Follower stops trusting the leader"]
    E --> F["Follower becomes a candidate and starts discovery"]
    F --> G["Pre-vote and election as in the earlier chapters"]
Figure 8: The leader check loop from a follower’s point of view. Repeated failures lead to a new election.
Everyday Analogy

In a classroom, the teacher takes attendance every morning, which is the follower check, and students glance at the teacher’s chair to see whether the teacher is still in the room, which is the leader check. One late answer is ignored, because someone may just be sleepy. Three misses in a row change the story: the teacher marks the student absent, or the students decide that the teacher has gone and choose a stand-in.

Fast detection when a node shuts down cleanly

If a node is stopped in a normal way, or the process crashes and the operating system closes its network connections, the other nodes notice the closed connection immediately. They do not have to wait for the timeouts. This is why an ordinary restart of a master usually leads to a new leader within a few seconds. The slow case is a machine that freezes or a network that silently drops packets. There, nothing closes, and the other nodes must wait for the timeouts to run out.

A slow node looks like a dead node

The checks cannot tell the difference between a dead node and a node that is alive but too busy to answer within the time limit. A long garbage collection pause, a heavily loaded machine, a virtual machine that was paused during maintenance, or a swapped-out process can all make a healthy node miss enough checks to be removed. This explains why leaders that are also busy data nodes are riskier, and why dedicated master nodes with modest loads are more stable.

What the leader does with a lost node

When the master’s follower checks fail, the master publishes a new cluster state without that node. Shards that lived on the lost node are then handled: replicas on other nodes are promoted to primaries where needed, and missing replica copies are rebuilt elsewhere, though only after a delay controlled by the delayed allocation setting, which is one minute by default, so that a brief restart does not trigger a big data movement.

Do not make the checks too aggressive

Lowering timeouts and retry counts makes failures detected faster, but it also makes the cluster more likely to react to short hiccups. In a cluster where nodes pause occasionally, aggressive settings cause a cycle: a node is removed, rejoins, is removed again, and every step triggers cluster state changes and shard movements. The defaults strike a good balance. Change them only with clear evidence and testing.

!
Flapping

When a node repeatedly leaves and joins the cluster, operators call it flapping. It is a sign of trouble in the node or the network, not in the election. Find the cause, such as long pauses or packet loss, instead of just loosening the timeouts.

15What Happens When the Master Fails: A Failover Timeline

Let us follow one failure from the first missed heartbeat to the moment the cluster is fully back to normal.

Imagine a cluster with three dedicated master-eligible nodes, called A, B, and C, and several data nodes. Node A is the elected master. Suddenly, node A’s machine loses power.

1

The master disappears

Node A stops answering. If its connections closed, the others know at once. If the machine froze silently, they must wait for check timeouts.

2

The cluster enters a leadership gap

Followers stop trusting the leader. For the cluster, a protective block applies: writes are rejected, and structural changes wait. Reads on existing shards continue where the shard copies are available.

3

Candidates start discovery

Nodes B and C become candidates, and each probes the other. Data nodes also notice the missing master and start looking for a new one.

4

Pre-vote and election

After random waits, one of them, say B, gets a positive pre-vote from C, starts a new term, and gathers a vote from C. Two out of three is a quorum.

5

The new leader publishes

Node B publishes a cluster state naming itself master. Node C accepts. The election is complete, and the block is lifted.

6

Data nodes rejoin the new leader

Data nodes connect to B, and it sends them the current state. Structural changes work again.

7

The lost node is handled

If node A also held data, the new master removes it from the cluster, promotes replicas for the primaries it held, and rebuilds missing copies after the delay.

8

Node A returns later

When A is repaired, it starts as a candidate, sees a leader with a higher term, joins as a follower, and receives the latest cluster state.

sequenceDiagram
    participant A as Node A: old master
    participant B as Node B
    participant C as Node C
    participant D as Data nodes
    A--xB: Power lost, no more replies
    B->>B: Leader check fails, become candidate
    C->>C: Leader check fails, become candidate
    B->>C: Pre-vote request
    C-->>B: Yes
    B->>C: Vote request for a new term
    C-->>B: Vote granted
    B->>C: Publish state naming B as master
    B->>D: Publish state naming B as master
    D-->>B: Joined new master
    A->>B: Later: A restarts and joins as follower
Figure 9: A failover in a three-master cluster. The two survivors form a quorum, elect a new leader, and later welcome the old leader back as a follower.
Everyday Analogy

A relay team’s captain twists an ankle in the middle of the race. The runners on the track keep running, because they already know their lanes. The remaining two officers quickly agree on who takes over as captain, and the new captain announces the change to the team. When the old captain recovers, they rejoin as a normal team member. The race never stopped, but changes to the race plan waited for a short while.

What clients see

During the gap, applications may see errors that mention a missing master, such as “master not discovered” or a cluster block named “no master.” Searches on existing indices often keep working, because they are answered by data nodes using the last known routing information. Writes are rejected by default, since a cluster that cannot change its structure must not accept writes that might depend on it. Good clients retry with a short delay, and the problem disappears within seconds once a new master is elected.

How long does it take?

PhaseTypical durationWhat decides it
Noticing the failureImmediate for a closed connection, up to about half a minute for a silent freezeFault detection timeouts and retry counts
ElectionA fraction of a second to a few secondsRandom delays, network speed, and number of candidates
Publishing the first stateMilliseconds to secondsCluster state size and number of nodes
Rejoining of all nodesSecondsSize of the cluster and network health
Shard recovery, if a data node was lostMinutes or more, after the delay of about one minuteAmount of data to copy and cluster load

The no-master block

While a cluster has no elected master, a block prevents operations that could cause harm. The setting cluster.no_master_block defaults to write, which rejects writes while allowing reads based on the last known state. Setting it to all also rejects reads and other operations. The default suits most cases, because it preserves availability for searching while protecting data changes.

i
Design your clients for the gap

Give your applications sensible retry rules with growing delays, and set request timeouts a bit longer than a normal failover. A tiny gap then passes unnoticed, and users never see an error.

16Do Not Confuse: Master Election and Primary Shard Promotion

Two different kinds of leadership exist in Elasticsearch. Mixing them up leads to wrong conclusions during incidents.

Master election chooses the leader of the cluster. There is a second, separate idea: for every shard, one copy is the primary, and the others are replicas. All new writes to a shard go first to its primary, which then copies them to the replicas. When a node holding a primary fails, one of its replicas is promoted to become the new primary. This is called primary promotion, and it is not an election in the sense of this guide.

AspectMaster electionPrimary shard promotion
What is chosenThe leader of the whole clusterThe main copy of one shard
Who decidesThe master-eligible nodes, by majority voteThe elected master, by a decision recorded in the cluster state
How many leadersOne per clusterOne primary per shard, so many in total
TriggerThe master is missing or unreachableThe node holding a primary is lost
Which copies are eligibleMaster-eligible nodesReplica copies that are in sync with the primary
Effect on clientsStructural changes and writes pause brieflyWrites to the affected shard pause briefly
Everyday Analogy

A school has a principal, who leads the whole school, and each classroom has a class monitor who leads that room. If a class monitor is absent, the principal appoints a substitute from the same class. If the principal is absent, the teachers meet and choose a new one. The two decisions happen at different levels, and a missing class monitor does not need a school-wide vote.

Connection between the two

The two ideas are linked through the master. Only an elected master can decide to promote a replica. If both a master and a data node fail at the same time, first a new master is elected, and then that master promotes replicas. In-sync replicas are tracked carefully so that a promoted copy contains every acknowledged write. This is why keeping at least one replica of important indices is a wise design, and why a healthy master is a precondition for repairing the data layer.

Cluster status colors

You may have seen the cluster health colors. Green means all primary and replica shards are assigned. Yellow means all primaries are assigned but some replicas are not. Red means at least one primary is unassigned. These colors describe the state of shards, not the state of the election. A cluster with a perfectly healthy master can still be red if data nodes are missing, and a cluster with no master cannot report health at all until a master is found.

Why the difference matters during incidents

When people say “the master failed” while they mean “a node holding primaries failed,” they start looking in the wrong place. Ask two questions first. Is there an elected master right now? That is a question about elections. Are the shards assigned? That is a question about allocation and promotion. The answers lead to different actions.

i
Quick check

The compact node listing marks the elected master with an asterisk, and a dedicated call shows the current master by name. If it returns a node, the election problem is solved, and you can turn to shard allocation.

17Adding, Removing, and Restarting Master-Eligible Nodes Safely

Most master-related outages during normal life are caused by human changes, not failures. A few simple habits avoid all of them.

Adding a master-eligible node

To add a master-eligible node to a running cluster, start it with the same cluster name, the seed hosts pointing to existing nodes, and the master role in its roles. Do not set the initial master nodes list on it, because the cluster is already formed. When the node joins, the elected master will include it in the voting configuration if that keeps an odd number of voters. Watch the logs of the new node to see that it joined and check that the cluster state shows it.

Removing a master-eligible node

Follow the safety rule from Chapter 7: stop fewer than half of the voters at once, wait for the automatic adjustment between removals, and use exclusions when removing half or more. Removing nodes carelessly is the number one way to lose a quorum by accident.

Rolling restarts

A rolling restart means restarting nodes one at a time, for example to change a setting or to update software, while the cluster stays online. The steps for master-eligible nodes follow a rhythm.

1

Check that the cluster is healthy

Confirm that there is an elected master, all nodes are present, and shards are in a green or expected state.

2

Limit shard movement

Temporarily restrict shard allocation so that the cluster does not start copying data when a node briefly leaves.

3

Restart one node

Stop it cleanly, apply the change, and start it again. If it is the elected master, a quick election will happen, which is normal.

4

Wait for it to rejoin

Check the logs and the node list until it is back in the cluster and the cluster is stable.

5

Repeat for the next node

Only then move to the next one. Never restart two of three voters at the same time.

6

Restore normal allocation

When all nodes are back, lift the temporary restriction and wait for the cluster to return to green.

Everyday Analogy

Changing the tires of a bus while passengers stay on board means lifting one wheel at a time. If you lift two wheels on the same side, the bus tips. The rolling restart is one wheel at a time, with a check in between. For a three-voter cluster, stopping two voters at once takes away the majority and the bus tips.

Order for version upgrades

For upgrades to a newer version, Elastic publishes a specific order in its documentation, and it generally places master-eligible nodes in the sequence that keeps a newer node from leading an older group. Always follow the documented order for your versions, and take a snapshot first.

Never clone a node with its data

Every node stores a unique identity on its data path. Copying a node’s entire data directory to create a second node produces two nodes with the same identity, which confuses membership and can corrupt votes. Create new nodes with empty data directories and let them join normally. If you must move a node to new hardware, move its data path and retire the old machine completely so that the identity exists only once.

Do not wipe the data path of a master-eligible node lightly

A master-eligible node stores its term, its latest accepted state, and its voting memory on disk. If you delete that directory and start the node again, it comes back as a stranger with no memory. In a cluster with a healthy majority, it can rejoin and receive the state. But wiping the data paths of several voters at once can destroy the cluster’s history and leave you with tools of last resort, as described in Chapter 25.

!
Plan before you touch

Before any change to master-eligible nodes, write down how many voters exist, how many you will touch, and what you will check after each step. Two minutes of planning avoid hours of recovery.

18Architecture: Where to Place and How to Size Master Nodes

Good master election starts with good architecture. The number, size, and location of master-eligible nodes decide how well the cluster survives trouble.

Common layouts

LayoutMaster-eligible nodesBest forMain risk
Single node1, also holding dataDevelopment and testsNo fault tolerance at all
Small shared cluster3 nodes that also hold dataSmall production workloadsHeavy queries can starve the master and cause elections
Dedicated masters3 dedicated master nodes plus data nodesMost production clustersLow, if the three are spread over failure zones
Extra-resilient5 dedicated master nodesVery critical or very large clustersSlightly slower coordination than three
Two zones with a tiebreaker1 master-eligible in each of two zones plus 1 small voting-only node in a third placeEnvironments with only two full data centersThe tiebreaker location must be truly independent

Spread across failure zones

A failure zone is a group of machines that can fail together, such as a rack, a data center room, or a cloud availability zone. To survive the loss of a whole zone, put the master-eligible nodes in at least three zones, one or more in each, so that the loss of any one zone still leaves a majority.

flowchart LR
    subgraph Z1["Zone 1"]
        M1["Master-eligible node 1"]
        D1["Data nodes"]
    end
    subgraph Z2["Zone 2"]
        M2["Master-eligible node 2"]
        D2["Data nodes"]
    end
    subgraph Z3["Zone 3"]
        M3["Master-eligible node 3"]
        D3["Data nodes"]
    end
    LB["Load balancer or API gateway"] --> D1
    LB --> D2
    LB --> D3
    M1 --- M2
    M2 --- M3
    M1 --- M3
Figure 10: One master-eligible node in each of three zones. If any single zone fails, two voters remain, which is still a majority.
Everyday Analogy

A company keeps its three keyholders in three different buildings. If one building is flooded, two keyholders remain and can still open the safe together. If all three keyholders lived in the same building, one flood would lock everyone out. Spreading the voters across zones is the same idea.

Hardware for master nodes

  • Modest CPU. Dedicated masters do little computation, though large clusters need more when the state is big and changes are frequent.
  • Enough memory for the state. Heap must hold the cluster state and its copies during updates. Bigger clusters with many shards need more. Use monitoring of heap and garbage collection to size it.
  • Fast, reliable disk. The master saves accepted states to disk before it answers, so slow disks slow every change. Small but fast local storage is best.
  • Stable network. Low, steady latency between master-eligible nodes matters more than high bandwidth.
  • No swapping. A node that swaps pauses unpredictably and can miss heartbeats. Lock memory or disable swap on master nodes.
  • Isolation from noisy neighbors. Avoid sharing the machine or the virtual host with heavy workloads.

How many master-eligible nodes?

Three is the usual answer. Five gives more tolerance but a little more coordination work. More than five is almost never useful. Adding data nodes does not mean adding master-eligible nodes: the number of voters should stay small even when the cluster grows to hundreds of nodes.

Separate roles in bigger clusters

In a large cluster, separating roles pays off. Dedicated masters keep leadership calm, dedicated coordinating nodes take the burden of merging big search results, and data nodes focus on shards. Ingest and machine learning roles can live on their own nodes as well. Every heavy activity that leaves the master alone makes elections less likely.

i
Managed platforms

Managed Elasticsearch services and orchestration tools often choose dedicated master nodes and zone placement for you. It is still worth learning what they chose, so that you can read their health signals and understand their limits.

19Performance and Scalability of the Master

The election itself is cheap. What decides whether the master stays calm is the size of the cluster state and the rate of changes it has to process.

Because there is only one elected master and it handles every structural change one after another, it is a natural bottleneck for control-plane work. This is not a flaw: the design trades some speed for safety. But it means that you must keep the master’s workload reasonable as the cluster grows.

What makes the master busy

Size

A large cluster state

Thousands of indices, many fields, and hundreds of thousands of shards make each state bigger, and each publication slower.

Rate

Frequent changes

Creating many indices per minute, frequent mapping updates, and constant shard movements each become a queued task.

Fan-out

Many nodes

Every state must reach every node. More nodes mean more messages and more waiting for the slowest one.

Extras

Management jobs and polling

Lifecycle, snapshot, and monitoring tasks add work, and some cluster-level information calls are routed through the master.

Shard count is the biggest lever

Every shard is an entry in the routing table, and every shard change is a state update. A cluster with an enormous number of small shards forces the master to track and update a lot of information for very little data. Elasticsearch has a default guard of one thousand shards per data node for most data nodes, set by cluster.max_shards_per_node. Staying comfortably below the guard, and using fewer, larger shards, is one of the most effective ways to keep the master healthy.

Everyday Analogy

A librarian who keeps the catalog for a library of ten thousand large books has a light job. If the same content is split into ten million tiny pamphlets, each needs its own catalog card, and every move of a pamphlet needs a new card. The number of books did not change, but the paperwork exploded. Shards are the pamphlets, and the routing table is the catalog.

Keep mappings under control

Each index carries its mapping in the cluster state. Indices with thousands of fields multiply that size, and uncontrolled dynamic fields make the state grow with incoming data. Protective measures include strict or limited dynamic mapping, a cap on the number of fields per index through index.mapping.total_fields.limit, and careful design so that data values are never used as field names.

Handle index creation at a healthy pace

Systems that create a new index for every small group of documents, such as one index per customer per day, can create thousands of new indices and shards each day. Using data streams with sensible rollover rules and shared indices for small tenants reduces the number of structural changes the master must handle.

Batching and priorities

The master groups similar tasks and orders tasks by priority. This helps, but it cannot make a huge queue vanish. If tasks arrive faster than they can be processed, the queue grows, and structural changes start to wait. The pending tasks list and the maximum waiting time in the health output show how deep the queue is.

Latency between master-eligible nodes

Each publication needs a round trip to a majority of voters. If master-eligible nodes are far apart, each change takes longer, and the timeouts of fault detection may be reached during ordinary network delays. For this reason, Elastic advises against stretching a single cluster across distant regions. For multi-region designs, use separate clusters connected by cross-cluster features, so that each region has its own quick elections.

Scaling the number of voters

More voters mean more messages per election and per publication, and a slightly bigger chance that one of them is slow. That is why three or five is recommended. The cluster can grow to many hundreds of nodes with the same three voters, as long as the state stays manageable.

i
Measure the master separately

Track heap use, garbage collection time, and cluster state publication time for the elected master and the other master-eligible nodes. Signs of stress appear there first, before users notice anything.

20Security Considerations

Whoever controls the master controls the structure of the cluster. Elections must therefore be protected from strangers, from mistakes, and from misuse.

The election runs over the transport layer, the private channel that nodes use to talk to each other. If that channel is open and unauthenticated, anybody who can reach it may pretend to be a node. A stranger with the master role could join, cast votes, and possibly influence the cluster. Securing elections means securing this channel and the people who may operate it.

RiskWhat could happenProtection
A rogue node joins the clusterIt receives cluster state, shard data, and possibly a voteTransport TLS with mutual certificate checks so that only trusted nodes can join
Traffic between masters is read or alteredMetadata and votes are exposed or changedEncrypt the transport layer and use strong protocol versions
Misuse of administrative callsSomeone changes voting exclusions or cluster settings and causes an outageLimit cluster management privileges to a small group of operators and service accounts
Theft of a master node’s diskMetadata such as index names and mappings is exposedDisk or volume encryption and strict file permissions
Denial of service against the masterHeavy requests slow structural changes or cause electionsRate limits at the gateway, separate coordinating nodes, and dedicated masters that clients cannot reach directly
Cloud credentials for discovery are too broadA leaked key reveals or changes more than machine addressesUse read-only, narrowly scoped credentials and keep them in the secure keystore
Everyday Analogy

A school election works only if the voters are really students of the school. If anyone from the street could walk in and cast a vote, the result would mean nothing. Requiring a student badge at the polling station is the transport TLS of the cluster, and only badge holders get a ballot.

Network design

Place master-eligible nodes on a private network segment. Allow the transport port only between nodes of the cluster. Do not expose master nodes to client traffic at all. Clients reach the cluster through a load balancer or an API gateway that points at data or coordinating nodes. This keeps user requests away from the leader and reduces the attack surface.

Operators and privileges

Some operations can affect leadership directly. Voting configuration exclusions, cluster settings that change fault detection, and shard allocation settings all belong to the cluster management privilege. Give this privilege to a small, trusted group, protect their accounts with strong authentication, and record their actions in an audit trail. A mistaken setting by one operator can have the same effect as an attack.

Protecting stored state

The cluster state saved on master-eligible nodes describes the structure of your data: names of indices, fields, and settings. This is often sensitive in itself. Protect it with disk encryption, restrict access to the data directory to the Elasticsearch service account, and treat backups of these directories with the same care as backups of data.

Certificates and elections

Because election traffic depends on certificates, an expired certificate can stop nodes from talking and lead to a leaderless cluster. Monitor certificate expiry on all master-eligible nodes as part of your normal health checks. Where possible, automate renewals.

Audit and change control

Treat changes to master nodes, roles, seed hosts, and voting settings as controlled changes: request, review, apply, and record. A written history helps you find the cause when leadership behaves oddly, and it helps auditors see that the cluster is managed with care.

!
Security is also availability

An attacker does not need to steal data to hurt you. Making leadership unstable is enough to stop structural changes and cause errors. Protect the master as you protect your data.

21Monitoring, Logging, and Metrics

A stable master is a quiet master. A handful of signals tells you when it stops being quiet, often long before users notice.

Questions the tools answer

QuestionWhere to lookWhat healthy looks like
Who is the elected master right now?The master call and the node listing, which marks the master with an asteriskExactly one node is named, and it is one you expect
How often does the master change?Log lines about master changes, and monitoring historyRarely: once in weeks, or only during planned work
Is the master keeping up?The pending tasks list and the queue fields of the cluster health callShort or empty queue, tasks wait milliseconds
How long do cluster state updates take?Node statistics for discovery, and log lines about slow publicationsPublication times of well under a second in most clusters
Are all nodes present?The health call’s node counts and the node listingThe number matches your plan
Is the master stable overall?The health report in newer versions, with a master stability indicatorGreen status with no diagnosis
Are master-eligible nodes under pressure?Heap, garbage collection time, CPU, and disk latency of those nodesLow and steady values with no long pauses

Important log lines

Log message ideaMeaning
Elected as masterThis node won an election. It states how many nodes joined and in which term.
Master node changedA node saw a different master than before. Compare timestamps across nodes.
Node left, node joinedMembership changed. Check whether it was planned.
Master not discovered yetThis node cannot find a master. The message lists what it found and what it still needs.
Failed to joinA node tried to join a leader and was refused or timed out. The reason follows in the message.
Leader check or follower check failedHeartbeats are failing. A node or the network is in trouble.
Publication took too long, or cluster state task exceeded a thresholdThe master or a node is slow. Look at state size and load.
Node is laggingA node did not apply a committed state in time and may be removed.
Everyday Analogy

A school keeps a logbook where the office records every change of principal, every teacher who left or joined, and every day the bell rang late. Most weeks the book has almost nothing in it, and that is the sign of a well-run school. A book full of entries about who is in charge is a warning that something is unsettled.

Metrics worth charting

  • Number of master changes over time. The simplest and best stability measure.
  • Term number. A rising term signals repeated elections.
  • Pending tasks and maximum wait. Show how deep the master’s queue is.
  • Cluster state size and publication time. Show growth of the control-plane workload.
  • Node count. A sudden drop or repeated changes point to membership problems.
  • Heap and garbage collection on master-eligible nodes. Long pauses are the top cause of unwanted elections.
  • Unassigned shards and recovery activity. Show the effect of leadership problems on data.

Alerts that help

Create a small set of alerts. First, an alert when the cluster has no elected master for more than a short period, such as thirty seconds. Second, an alert when the master changes more than a few times in an hour. Third, an alert when pending tasks wait longer than a set limit for several minutes. Fourth, an alert when a master-eligible node reports long garbage collection pauses. Fifth, an alert for the number of nodes falling below the expected count. Each alert should link to a short runbook.

Watching a single node’s view

Some issues appear only from the perspective of one node, for example a node that is cut off from the others and keeps logging “master not discovered.” Central log collection lets you compare what each node saw at the same moment, which usually tells the whole story of an incident in minutes.

i
Write the baseline down

Record what a normal week looks like: how many master changes, how long the queue is, how big the state is. Deviations from your own baseline are easier to spot than deviations from a generic rule.

22Advantages, Disadvantages, and Trade-offs

No design is perfect. Here is an honest scorecard for the majority-vote election so that you can decide where to invest effort.

Advantages

  • Prevents split brain, so two leaders can never exist at once.
  • Elects a new leader automatically, usually within seconds.
  • Manages the voting configuration itself, removing a dangerous manual setting.
  • Never forgets a committed change, because voters refuse out-of-date candidates.
  • Pre-voting keeps healthy clusters from being disturbed by returning nodes.
  • Randomized delays avoid endless split votes.
  • Keeps searches on existing data working during a leadership gap.
  • Built in, with no external coordination service to run.

Disadvantages

  • A minority side of a network split pauses structural changes and rejects writes.
  • Needs at least three master-eligible nodes for real fault tolerance.
  • A single master is a bottleneck for structural changes in very large clusters.
  • Slow or paused nodes look like dead nodes and can cause unneeded elections.
  • Wrong bootstrapping can create a second cluster by accident.
  • Losing a majority of master-eligible nodes with their data needs risky recovery tools.
  • Stretching across distant sites is a poor fit because of latency.
  • Dedicated masters add cost and operational parts.

The central trade-off: consistency against availability

When a network split happens, a distributed system must choose between staying available on both sides and staying consistent. Elasticsearch’s election chooses consistency for the cluster’s structure. The side with a majority carries on, and the side without one stops changing the cluster. This costs some availability on the minority side, but it keeps the structure of the cluster correct, which is usually the right choice for a system that stores important data.

The second trade-off: fast detection against stability

Quick failure detection restores leadership sooner but reacts to short hiccups. Slow detection is calmer but leaves the cluster leaderless for longer during a real failure. The defaults aim for a balance, and changes should be based on measured behavior of your environment.

The third trade-off: dedicated masters against cost

Dedicated master nodes cost extra machines but give calm, predictable leadership. Sharing masters with data nodes saves money and works for small clusters, but a heavy query can push the master into a long pause and trigger elections. The larger and more critical the cluster, the more dedicated masters pay for themselves.

The fourth trade-off: three voters against five

Five voters survive two simultaneous failures, which matters for very critical services or for zone designs where one zone may fail while another is under maintenance. They also add a little coordination work and cost. Three is enough for most.

When this design is the wrong tool

If you need a service that stays fully writable on both sides of a network split, a majority-based design is the wrong choice, and you would look at systems built for that behavior. For search clusters that store data of record and derive it from other sources, the safe and simple election of Elasticsearch is a good match.

23Design Patterns for a Stable Master

A calm leadership does not happen by luck. These seven habits make elections rare, fast, and boring.

Pattern 1

Three dedicated masters in three zones

Use three small, dedicated master nodes, one in each failure zone. Any single failure leaves a majority, and leadership is never competing with data work.

Pattern 2

Voting-only tiebreaker

When you have only two real sites, add a small voting-only node in a third place so that a majority remains after a site failure.

Pattern 3

Bootstrap once, then remove

Use the initial master list only to create a new cluster, then remove it from all configuration files and templates so it never affects a later restart or a new node.

Pattern 4

Role separation

Keep data, ingest, coordinating, and master roles on separate nodes in bigger clusters, so heavy work never pauses the leader.

Pattern 5

Gradual change with exclusions

Change master-eligible nodes one at a time, and use voting exclusions for larger cuts, with a check after every step.

Pattern 6

A lean cluster state

Keep shard counts sensible, mappings strict, and index creation paced, so the master’s queue stays short and publications stay fast.

Pattern 7

Rehearse failover

In a test environment, stop the elected master on purpose and watch the election, the client behavior, and the alerts. Repeat until nobody is surprised.

Pattern 2 in action

A company has two data centers, each with one master-eligible node. On paper this gives two voters, which is no fault tolerance, because the loss of either one breaks the quorum of two. The team adds a small virtual machine in a cloud region as a voting-only node. Now there are three voters. If either data center fails, the surviving center plus the tiebreaker form a majority of two out of three, and the cluster continues. The tiebreaker never becomes master and needs almost no resources.

Pattern 7 in action

A platform team runs a failover drill every quarter. They stop the elected master in a staging cluster during a load test, measure how long clients see errors, and check that alerts fire. The first drill reveals that one application does not retry on a missing master error. They fix it. By the third drill, the failover passes without any visible effect. The drill costs an hour and replaces guesswork with evidence.

A pattern for documentation

Write a one-page runbook that lists the expected master-eligible nodes, their zones, how to identify the current master, how to check the voting configuration, and what to do if there is no master. Keep it next to your alerts. During a real incident, nobody wants to think from scratch.

i
Keep configuration boring

The best election settings are the ones you never touch. Prefer defaults, keep the master-eligible set small and odd, and put your energy into stable machines and networks instead of clever tuning.

24Anti-Patterns and Common Mistakes

These are the traps that cause most master-related incidents. Each is common and easy to avoid once you know it.

ANTI-PATTERN 01Avoid
What people do

They run only two master-eligible nodes, or an even number such as four, believing that more is safer.

Why it hurts

Two voters cannot survive any failure of the one that holds the vote, and four voters tolerate no more failures than three. The extra node costs money and adds nothing.

Better approach

Use three master-eligible nodes, or five for very critical setups, and add a voting-only tiebreaker if you only have two sites.

ANTI-PATTERN 02Avoid
What people do

They leave the default roles on every node, so that all fifty nodes of a big cluster are master-eligible.

Why it hurts

Elections and every published state must reach many voters, and any of the many busy nodes can be elected while running heavy queries. Leadership becomes slow and fragile.

Better approach

Choose roles on purpose. Keep a small, odd number of master-eligible nodes and give every other node explicit non-master roles.

ANTI-PATTERN 03Avoid
What people do

They keep the initial master nodes setting in their configuration templates, and it ends up on new nodes that should join an existing cluster.

Why it hurts

A new node with a fresh data path and that setting may bootstrap a separate cluster of its own with the same name. It then refuses to join the real one because the cluster identities differ.

Better approach

Use the setting only for the first start of a brand-new cluster, and remove it afterward. Point new nodes to the existing cluster with seed hosts only.

ANTI-PATTERN 04Avoid
What people do

They restart or replace half or more of the master-eligible nodes at the same time to finish a maintenance window quickly.

Why it hurts

The remaining voters no longer form a quorum, so no leader can be elected. The cluster stops accepting structural changes until enough voters return.

Better approach

Change one master-eligible node at a time, wait for stability between steps, and use exclusions for larger cuts.

ANTI-PATTERN 05Avoid
What people do

They stretch a single cluster over distant regions, with master-eligible nodes far apart.

Why it hurts

Latency and packet loss between regions slow every publication and make heartbeats miss their timeouts. The cluster suffers from frequent elections and slow changes.

Better approach

Run a cluster per region and connect clusters using cross-cluster features for search and replication.

ANTI-PATTERN 06Avoid
What people do

They make fault detection very aggressive to detect failures faster, or they ignore nodes that repeatedly leave and rejoin.

Why it hurts

Short pauses are treated as failures. Nodes are removed, shards move, and the cluster spends its effort on repair instead of service. The real cause, often long garbage collection or a bad network link, stays hidden.

Better approach

Keep the defaults, and find and fix the reason for the pauses or packet loss.

ANTI-PATTERN 07Avoid
What people do

They let master-eligible nodes also hold big shards and serve heavy searches on small machines.

Why it hurts

A long garbage collection pause or a saturated disk on such a node stops heartbeats and can trigger elections during business hours, at exactly the moment of highest load.

Better approach

Use dedicated master nodes with modest but reliable resources as the cluster grows.

Other frequent mistakes

  • Deleting the data directory of master-eligible nodes to “reset” them without understanding the consequences.
  • Cloning a node with its data directory and running both copies.
  • Using different seed host lists on different nodes, so that some nodes cannot find the leader.
  • Following advice from old articles about minimum master nodes on modern versions.
  • Ignoring the size of the cluster state until the master falls behind.
  • Never testing what happens when the master disappears.

25Failure Scenarios and Recovery

Most master problems fall into a few patterns. Each has a calm recovery, and the last resort is rarely needed.

flowchart TD
    A["Cluster reports no master"] --> B{"Are a majority of the master-eligible nodes running and reachable?"}
    B -->|No| C["Restore the nodes or the network so that a majority can talk"]
    B -->|Yes| D{"Do their logs show that they found each other?"}
    D -->|No| E["Check seed hosts, ports, firewalls, and certificates"]
    D -->|Yes| F{"Do the logs mention a different cluster identity?"}
    F -->|Yes| G["A node bootstrapped on its own: fix bootstrap settings and data paths"]
    F -->|No| H["Look for long pauses, full disks, or a full heap on the voters"]
    C --> I["Only if nodes are permanently lost: consider last resort recovery tools"]
Figure 11: A calm triage path for a cluster without a master. Most cases end at the first two questions.

Scenario: a single master fails

This is the normal case, covered in Chapter 15. A majority remains, an election takes seconds, and the cluster continues. No action is needed except to repair the failed node and let it rejoin. Check that alerts fired and that clients coped.

Scenario: a majority of master-eligible nodes is down

If two of three voters are lost, the last one cannot elect a leader alone. The cluster stops changing its structure and rejects writes by default. The right response is to bring the lost nodes back, either by repairing the machines or by restoring the network. When enough voters return, an election happens on its own and the cluster recovers without data loss.

Scenario: a network partition

The side with a majority keeps a master. The other side pauses. Recovery is to repair the network. When the sides can talk again, the paused nodes join the leader and catch up. Nothing needs to be deleted. Review why the network failed, and consider whether your zone layout matches the failure patterns you actually have.

Scenario: garbage collection storms and slow disks

If voters pause for long periods, heartbeats fail, leaders are lost, and elections repeat. Find the pauses in the garbage collection logs and the slow disk operations in system metrics. Move heavy work away from master-eligible nodes, right-size their heap, disable swapping, and use fast local disks.

Scenario: a node bootstrapped a separate cluster

A new node started with the initial master nodes setting and an empty data path may form its own one-node cluster with the same name. It will never join the real one, because the cluster identities do not match. Stop the node, remove the initial master nodes setting, wipe its data path if it holds nothing worth keeping, and start it again with seed hosts pointing to the real cluster.

Scenario: certificate or credential expiry

If transport certificates expire, nodes cannot complete handshakes with each other, and elections fail even though every machine is running. Renew certificates on the affected nodes, and rely on file reloading or restart as needed. Add expiry alerts so that this cannot surprise you again.

Scenario: disk full on a master-eligible node

A master-eligible node needs disk space to save its accepted states. If its disk is full, it cannot persist the state, and it may fail to acknowledge publications or even fail at startup. Free space, and put logs on a different volume so that a noisy log cannot fill the disk of the node.

Everyday Analogy

Think of a jury that needs at least seven of twelve members to reach a verdict. If only five show up, the court simply waits, because deciding with five would be unfair. The court does not need to do anything clever. It needs two more jurors to arrive. Losing a quorum works the same way: the safe action is to wait for enough voters to come back.

Last resort: when voters are lost forever

Sometimes a majority of the master-eligible nodes are lost for good, for example because their disks were destroyed. No election can ever succeed, because the surviving voters are too few. Elasticsearch ships an offline tool, elasticsearch-node, that can force recovery in this situation. Its unsafe bootstrap command tells a surviving master-eligible node to form a new voting configuration from itself, and other nodes must be told to detach from their old cluster identity before they can join the new one.

The word unsafe is deliberate. This procedure abandons the safety guarantees of majority voting. It can lose recent committed changes, and it may bring back state that was already superseded. Use it only after you have tried everything else, with a snapshot or a copy of the data directories taken first, following the documentation for your exact version step by step. Often, the safer choice is to restore from a snapshot into a fresh cluster.

!
Do not improvise

Unsafe recovery tools are not for experiments. Take copies of the data directories, involve a second pair of eyes, and write down every step. A wrong move in this procedure can turn a recoverable problem into a permanent one.

Habits that make recovery easier

  • Regular snapshots of important indices, tested by restoring them.
  • Copies of configuration files and certificates in a safe place.
  • A record of which nodes are master-eligible and where they live.
  • Runbooks for the no-master case, written and reviewed in calm times.

26Troubleshooting Common Master Problems

When something looks wrong, match the symptom to its likely meaning. This table covers the messages and behaviors that people meet most often.

What you seeMost likely meaningFirst things to check
Master not discovered yet, this node has not previously joined a bootstrapped clusterA brand-new node cannot find enough founding votersThe initial master nodes list, node names, seed hosts, ports, and firewalls
Master not discovered or elected yet, an election requires nodes with certain idsThe cluster has no quorum, or nodes cannot reach each otherWhich voters are running, network paths, and certificates
Master not discovered exception or a cluster block for no master in client responsesThe request reached a node that sees no leaderWhether a majority of voters are alive, and retry after a few seconds
Master changes every few minutesLeadership is unstableGarbage collection pauses, packet loss, overloaded voters, and too tight fault detection settings
A node cannot join and mentions a different cluster identityThe node was bootstrapped separately or belongs to another clusterIts data path, its bootstrap settings, and its cluster name
Pending tasks keep growingThe master is overloaded or slow to get acceptancesState size, shard counts, mapping growth, and slow nodes
Publication took too long, or a node is laggingA node is slow to apply the stateThat node’s load, heap, and disk, and network delays to it
One node repeatedly leaves and joinsFlapping caused by pauses or network trouble on that nodeIts garbage collection log, system logs, and network
Cluster stays yellow or red after a master changeShard recovery is still in progress, or a data node is missingNode count, unassigned shards, and allocation explanations
New index creation is very slowThe master queue is deepPending tasks list and state size

A calm way to debug

1

Ask who the master is

Call the master endpoint from several nodes. If different nodes name different masters, or none, you have a partition or a bootstrap problem.

2

Count the voters

List the master-eligible nodes, see which are running, and compare with the voting configuration.

3

Read the logs of every voter

Start with the moment of the first problem. The messages usually say what the node found and what it is waiting for.

4

Check the environment

Look at the network, disks, memory, garbage collection, certificates, and recent changes to the machines or the configuration.

5

Change one thing at a time

Fix one suspected cause, wait, and observe. Several changes at once hide which one helped.

6

Record the finding

Add the symptom and the fix to your runbook so that the next person solves it in minutes.

i
A quick self-test

In a test cluster, stop the elected master and watch. Within seconds, another node should be named master, and client errors should end. If they do not, you have learned something valuable before it mattered.

27Real-World Scenarios

Here are four common situations, with rough numbers, showing master election at work. The companies are imaginary, but the patterns are the ones teams meet every day.

Scenario 1: A zone goes dark

The imaginary video platform StreamHarbor runs three dedicated master nodes, one in each of three availability zones, and forty data nodes spread over the same zones. One evening, a whole zone loses power. The two remaining masters detect the lost leader within seconds because its connections closed, and one of them wins the election in under a second. Users see a few failed writes that succeed on retry. The on-call engineer receives an alert about missing nodes, not about a missing master, and the recovery of shards proceeds without drama.

Scenario 2: Two rooms and no tiebreaker

At the imaginary firm LedgerLoop, a cluster has one master-eligible node in each of two rooms. When the power fails in room A, the remaining node in room B cannot form a quorum, because it holds only one of two votes. The whole cluster stops changing until room A returns. The team adds a small voting-only node in a third location. In the next power failure, room B and the tiebreaker form a majority, and the cluster carries on.

Scenario 3: The nightly election storm

The imaginary photo app PixelPost lets its six data nodes also be master-eligible. Every night at two o’clock, a heavy reporting query pushes one node into garbage collection pauses of twenty seconds. If that node is the elected master, the others lose the leader and elect a new one. Three times a week, the leadership moves between nodes during the report. The team introduces three small dedicated master nodes and moves the reports to a separate coordinating tier. The master changes drop from dozens per month to zero.

Scenario 4: The accidental second cluster

The imaginary retailer AtlasCart uses a configuration template that includes the initial master nodes list on every new machine. When engineers add a seventh node, it starts with an empty disk, sees the list, finds no other listed nodes reachable at that moment, and forms its own cluster of one. It refuses to join the real cluster with a message about a different cluster identity. The team removes the setting from the template and wipes the empty node’s data path, and the node joins normally.

A worked example with numbers

1

Set the scene

A cluster has five master-eligible nodes, so the quorum is three. Node E is the elected master in term 12. Nodes A and B sit in room 1, and nodes C, D, and E sit in room 2.

2

The link between the rooms fails

Room 2 keeps three nodes, including the master E. Room 1 keeps two nodes, A and B. Both rooms are still running normally on their own.

3

Room 1 loses its leader

A and B miss three leader checks in a row and become candidates. Their pre-vote finds only two possible votes, which is below the quorum of three, so neither starts a real election. They log that no master can be elected and wait.

4

Room 2 carries on

E continues as master in term 12. It still gets acceptances from C and D, so publications commit with three of five. Its follower checks to A and B fail, so it publishes a state that removes them from the cluster.

5

The link is repaired

After twenty minutes the network is back. A and B, still candidates, find E through discovery, see a leader with term 12, and join as followers.

6

Catch-up and recovery

A and B receive the latest cluster state. Shards that were on their data neighbors are recovered, and the cluster returns to green. No changes were made in two places, so nothing is discarded.

28Frequently Asked Questions

Q1What is master election in Elasticsearch?
It is the voting process by which the master-eligible nodes of a cluster choose exactly one leader, the elected master, that makes cluster-wide decisions such as creating indices and allocating shards. It runs at cluster start and whenever the master is lost.
Q2How many master-eligible nodes should I have?
Three for most production clusters, spread across three failure zones. Five can be used for very critical setups. Avoid two and avoid even numbers, because they give no extra fault tolerance.
Q3What happens if the master fails?
The remaining master-eligible nodes notice the loss, and if they hold a majority, one of them wins an election and becomes the new master, usually within seconds. During the gap, structural changes wait and writes are rejected by default, while reads on existing shards continue.
Q4What is split brain, and can it happen now?
Split brain means two parts of a cluster each elect their own master and diverge. Modern versions prevent it, because a master needs votes from a majority of the voting configuration, and two majorities cannot exist at the same time.
Q5Do I still need to set the minimum number of master nodes?
No. That setting belonged to the old Zen Discovery system before version 7.0. Modern versions manage the voting configuration automatically.
Q6What is the initial master nodes setting for?
It names the founding voters of a brand-new cluster so that the first election can happen. Use it only when creating a new cluster, and remove it afterward. Never use it on nodes that join an existing cluster.
Q7Does the master handle my searches and writes?
No. Searches and document writes go to data nodes directly. The master handles structural changes such as new indices, mappings, and shard allocation.
Q8What is a voting-only node?
A master-eligible node that votes in elections but can never be elected. It is a cheap tiebreaker, useful when you have two sites and need a third vote in another location.
Q9Why are odd numbers of master-eligible nodes recommended?
A quorum is a majority, and an even number of voters tolerates no more failures than the odd number below it. Elasticsearch keeps the voting configuration odd by leaving one node out when the count is even.
Q10How do I safely remove master-eligible nodes?
Stop fewer than half of the voters at a time, wait for the cluster to adjust between steps, and use the voting configuration exclusions feature when removing half or more.
Q11Why does my master keep changing?
Usually because the master or other voters are unreachable for short periods: long garbage collection pauses, overloaded machines, slow disks, or an unreliable network. Find the pauses or the packet loss instead of changing the timeouts.
Q12Is master election the same as primary shard promotion?
No. Master election picks the leader of the whole cluster. Primary promotion picks the main copy of a single shard from its replicas, and the elected master decides it.
Q13Can I stretch one cluster over several regions?
It is not recommended. Latency slows every cluster state update and can make heartbeats fail. Use one cluster per region and connect them with cross-cluster features.
Q14How can I see who the master is?
Use the master call, or the node listing where the elected master is marked with an asterisk. In newer versions, the health report also has an indicator for master stability.

29Summary and Key Takeaways

Master election is a simple idea with deep safety properties: one leader, chosen by a majority, replaced quickly when it disappears. Here is everything to remember.

Key Takeaways

  • What it is: the voting process by which master-eligible nodes pick exactly one elected master to manage the cluster state, run at cluster start and whenever the master is lost.
  • Why a majority: any two majorities overlap, so two leaders can never win at once, and split brain becomes impossible without any manual quorum setting.
  • How the vote works: a candidate discovers peers, waits a random delay, pre-votes, starts a higher term, collects votes from a quorum, and publishes a state naming itself master.
  • How failure is noticed: followers check the leader and the leader checks the followers every second, and repeated failures start a new election.
  • How to design for it: use three dedicated master-eligible nodes in three zones, add a voting-only tiebreaker when you have two sites, and keep roles separated.
  • How to operate it: change master-eligible nodes one at a time, use exclusions for larger cuts, bootstrap only once, and keep the cluster state lean.
  • How to watch it: chart master changes, term, pending tasks, state publication time, and pauses on master-eligible nodes, and rehearse a failover before you need one.

Keep in mind that setting names, defaults, and tools can change between Elasticsearch versions, so confirm exact details against the documentation of the release you run. With that habit, and the ideas in this guide, you can keep your cluster’s leadership steady, understand it when it moves, and recover it calmly when it does not.