Elasticsearch & Full Text Search Systems · Lezione

Allocazione e ribilanciamento degli shard

Comprenda come Elasticsearch decida dove collocare gli shard, come l'allocation awareness distribuisca le repliche sull'hardware e come controllare il ribilanciamento durante il ridimensionamento e la manutenzione.

Lezione 4 di 413 passaggi

Allocazione e ribilanciamento degli shard è una lezione Elasticsearch & Full Text Search Systems gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Elasticsearch & Full Text Search Systems, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Elasticsearch & Full Text Search Systems include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

Where Do Shards Go?

When you create an index or add a node, Elasticsearch must decide which node holds each shard. This process is shard allocation, and keeping it balanced is key to a healthy, performant cluster.

The Allocation Process

The master node runs allocation deciders for every unassigned shard. They check disk space, shard count, awareness rules, and filters before placing a shard. Failing any decider keeps the shard UNASSIGNED.

Primary vs Replica Placement

A replica is never allocated to the same node as its primary. This guarantees that losing one node cannot take out both copies of the same data. With one replica you survive any single-node failure.

Watching Allocation

Use the _cat/shards API to see where each shard sits and its state. STARTED means active; RELOCATING means it is moving.

GET _cat/shards?v

Explaining a Stuck Shard

When a shard will not allocate, the _cluster/allocation/explain API tells you exactly which decider blocked it and why. This is the first stop for debugging a yellow or red cluster.

GET _cluster/allocation/explain
{
  "index": "my_index",
  "shard": 0,
  "primary": false
}

Allocation Awareness

Allocation awareness spreads copies across physical boundaries like racks or availability zones. You tag nodes with custom attributes and tell the cluster to be aware of them.

cluster.routing.allocation.awareness.attributes: zone

Forced Awareness

Forced awareness goes further: it refuses to over-allocate replicas to surviving zones if a zone goes down, preventing one zone from holding all copies. This protects capacity planning during outages.

cluster.routing.allocation.awareness.force.zone.values: zone1,zone2

Shard Filtering

You can pin or exclude an index from specific nodes using allocation filters. This is handy for hot/warm architectures where older indices migrate to cheaper hardware.

PUT my_index/_settings
{
  "index.routing.allocation.require.box_type": "warm"
}

Rebalancing

After nodes join or leave, the cluster rebalances to even out shard counts. This is automatic but generates network and disk I/O, so it should be controlled during sensitive operations.

Pausing Allocation

Before a rolling restart, disable allocation so the cluster does not waste effort relocating shards from a node you are about to bring back. Re-enable it afterward.

PUT _cluster/settings
{
  "transient": {
    "cluster.routing.allocation.enable": "primaries"
  }
}

Throttling

Limit concurrent recoveries with cluster.routing.allocation.node_concurrent_recoveries and bandwidth with indices.recovery.max_bytes_per_sec to keep rebalancing from starving live queries.

Quick Check

Test your understanding of shard allocation.

Recap

You learned how shards are placed and balanced:

  • Allocation deciders choose shard locations; replicas avoid their primary's node.
  • Debug stuck shards with allocation/explain.
  • Allocation awareness and forced awareness spread copies across zones.
  • Use allocation filters for hot/warm tiers and disable allocation during rolling restarts.
Gratis per iniziare

Impara Elasticsearch & Full Text Search Systems con un tutor IA — gratis

Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.

Corsi
12
Lezioni
48

Domande Frequenti

La lezione «Allocazione e ribilanciamento degli shard» è gratuita?

Sì — il testo completo di «Allocazione e ribilanciamento degli shard» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Elasticsearch & Full Text Search Systems, passa a CoddyKit PRO. Il corso Elasticsearch & Full Text Search Systems include 4 lezioni in totale.

Cosa imparerò in «Allocazione e ribilanciamento degli shard»?

Comprenda come Elasticsearch decida dove collocare gli shard, come l'allocation awareness distribuisca le repliche sull'hardware e come controllare il ribilanciamento durante il ridimensionamento e l… Eserciti Elasticsearch & Full Text Search Systems con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Elasticsearch & Full Text Search Systems?

Non è richiesta alcuna esperienza precedente. Elasticsearch & Full Text Search Systems su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Allocazione e ribilanciamento degli shard»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Elasticsearch & Full Text Search Systems?

Sì. Ogni lezione Elasticsearch & Full Text Search Systems include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Partizionamento e repliche
  2. Stato e monitoraggio del cluster
  3. Ruoli dei nodi e architettura
  4. Allocazione e ribilanciamento degli shard
← Torna a Elasticsearch & Full Text Search Systems