AlgoViz

Elasticsearch shards, replicas and refresh

medium 4 min

A primary shard is a partition of an index.

Video lesson · Chapter 1 of 5

The merchant can read a missing search result

0:00 / 3:45

Four shards, one search page

1:21Reel

Theory

Read or listen first. About 1 min.

What it is

A search shard knows its local contenders. The coordinator needs enough scored candidates from every shard to discover the global winners before requesting full document bodies.

How four shards produce one results page

Shard A10 IDsShard B10 IDsShard C10 IDsShard D10 IDsMerge up to 40 IDsA shard can contribute any number of winners.
Each shard returns up to ten IDs and comparable scores. The coordinator receives at most forty small candidate records.

Why it exists

Moving IDs and scores first keeps losing documents off the network. The merge assumes the scores use a comparable scale across shards.

Words to know

Fetch phase
The stage that retrieves the full records for the globally selected search hits.

How it works

Step through the idea, or press Play.

Step 1 of 3

Fan out. Send the query to an eligible copy of each target shard.

Understand it

Worked example

Elasticsearch shards, replicas and refresh in practice

Across four shards, request each shard’s top ten for a global top ten, merge the returned candidates, then fetch the selected documents. A newly written document may need a refresh before appearing in search.

Related case

Why did this document rank first?

An internal engineering search returns a long glossary above a precise two-paragraph runbook. Another user cannot find a document they just published.

The missing reset guide
Finding the reset guideRunbookjust writtenIndexold viewResultsno guideSearch has an older index view

Check refresh, terms and access filters.

Sources