Alocação e rebalanceamento de fragmentos
Entenda como o Elasticsearch decide onde os fragmentos ficam, como a consciência de alocação distribui réplicas entre os equipamentos e como controlar o rebalanceamento durante o dimensionamento e a manutenção.
Alocação e rebalanceamento de fragmentos é uma aula grátis de Elasticsearch & Full Text Search Systems no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Elasticsearch & Full Text Search Systems, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Elasticsearch & Full Text Search Systems inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em 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?vExplaining 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: zoneForced 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,zone2Shard 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.
Perguntas Frequentes
A aula “Alocação e rebalanceamento de fragmentos” é grátis?
Sim — o texto completo de “Alocação e rebalanceamento de fragmentos” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Elasticsearch & Full Text Search Systems, atualize para CoddyKit PRO. O curso de Elasticsearch & Full Text Search Systems inclui 4 aulas no total.
O que vou aprender em “Alocação e rebalanceamento de fragmentos”?
Entenda como o Elasticsearch decide onde os fragmentos ficam, como a consciência de alocação distribui réplicas entre os equipamentos e como controlar o rebalanceamento durante o dimensionamento e a… Você pratica Elasticsearch & Full Text Search Systems com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Elasticsearch & Full Text Search Systems?
Nenhuma experiência prévia é necessária. Elasticsearch & Full Text Search Systems no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Alocação e rebalanceamento de fragmentos”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Elasticsearch & Full Text Search Systems?
Sim. Cada aula de Elasticsearch & Full Text Search Systems inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Fragmentação e réplicas explicadas
- Integridade e monitoramento do cluster
- Funções e arquitetura dos nós
- Alocação e rebalanceamento de fragmentos