0Pricing
Elasticsearch & Full Text Search Systems · Lección

Asignación y reequilibrado de shards

Comprenda cómo Elasticsearch decide dónde residen los shards, cómo allocation awareness distribuye las réplicas entre distintos equipos y cómo controlar el reequilibrado durante el escalado y el mantenimiento.

Asignación y reequilibrado de shards es una lección gratuita de Elasticsearch & Full Text Search Systems en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Elasticsearch & Full Text Search Systems, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Elasticsearch & Full Text Search Systems incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

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.

Preguntas frecuentes

¿La lección «Asignación y reequilibrado de shards» es gratis?

Sí — el texto completo de «Asignación y reequilibrado de shards» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Elasticsearch & Full Text Search Systems, actualiza a CoddyKit PRO. El curso de Elasticsearch & Full Text Search Systems incluye 4 lecciones en total.

¿Qué aprenderé en «Asignación y reequilibrado de shards»?

Comprenda cómo Elasticsearch decide dónde residen los shards, cómo allocation awareness distribuye las réplicas entre distintos equipos y cómo controlar el reequilibrado durante el escalado y el mant… Practicas Elasticsearch & Full Text Search Systems con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Elasticsearch & Full Text Search Systems?

No se requiere experiencia previa. Elasticsearch & Full Text Search Systems en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.

¿Cuánto tiempo toma la lección «Asignación y reequilibrado de shards»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Elasticsearch & Full Text Search Systems?

Sí. Cada lección de Elasticsearch & Full Text Search Systems incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Explicación de shards y réplicas
  2. Salud y monitorización del clúster
  3. Roles y arquitectura de los nodos
  4. Asignación y reequilibrado de shards
← Volver a Elasticsearch & Full Text Search Systems