Elasticsearch & Full Text Search Systems · Aula

Indexação em massa e a API Bulk

Indexe milhares de documentos com eficiência usando a API Bulk e aprenda a lidar com falhas parciais.

Aula 4 de 413 etapas

Indexação em massa e a API Bulk é 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.

Why Bulk

Indexing documents one HTTP request at a time is slow. The Bulk API packs many operations into a single request, dramatically improving throughput.

The NDJSON Format

Bulk requests use newline-delimited JSON: each action line is followed by its source line (for index/create/update). Every line ends with a newline, including the last.

A Basic Bulk Request

Here two documents are indexed in one call.

POST /products/_bulk
{ "index": { "_id": "1" } }
{ "name": "Keyboard", "price": 40 }
{ "index": { "_id": "2" } }
{ "name": "Mouse", "price": 20 }

Supported Actions

Bulk supports four actions:

  • index — create or replace
  • create — fail if the id exists
  • update — partial update
  • delete — no source line needed

Mixing Actions

A single bulk body can mix actions and even target different indices via the action metadata.

POST /_bulk
{ "delete": { "_index": "products", "_id": "3" } }
{ "update": { "_index": "products", "_id": "1" } }
{ "doc": { "price": 45 } }

Partial Failures

Crucially, the bulk request itself returns 200 OK even if some items fail. You must inspect the errors flag and per-item status.

// response
{ "errors": true, "items": [ { "index": { "status": 201 } },
  { "index": { "status": 409 } } ] }

Choosing a Batch Size

There is no perfect number, but 1,000 to 5,000 documents (or a few megabytes) per bulk request is a good starting range. Measure and adjust for your data.

Tuning for Heavy Loads

For huge initial loads, temporarily disable the refresh interval and reduce replicas, then restore them afterward.

PUT /products/_settings
{ "index": { "refresh_interval": "-1",
  "number_of_replicas": 0 } }

Restore After Load

Once the bulk load finishes, re-enable refresh and replicas so the data becomes searchable and durable.

PUT /products/_settings
{ "index": { "refresh_interval": "1s",
  "number_of_replicas": 1 } }

Retrying Failures

A status of 429 (too many requests) means the cluster is overloaded. Retry only the failed items with exponential backoff, not the whole batch.

Client Helpers

Official clients provide bulk helpers that chunk, send, and retry automatically, so you rarely build NDJSON by hand in production.

Quick Check

A bulk request returns HTTP 200. Is everything fine?

Recap

You learned the Bulk API: the NDJSON format, the four actions, why partial failures need per-item inspection, sensible batch sizes, load-time tuning of refresh and replicas, and retrying 429s with backoff.

Grátis para começar

Aprenda Elasticsearch & Full Text Search Systems com um tutor de IA — grátis

Escreva e execute código real no seu navegador, obtenha ajuda instantânea de um tutor de IA 24/7 e continue de onde parou na web ou no app.

Cursos
12
Aulas
48

Perguntas Frequentes

A aula “Indexação em massa e a API Bulk” é grátis?

Sim — o texto completo de “Indexação em massa e a API Bulk” é 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 “Indexação em massa e a API Bulk”?

Indexe milhares de documentos com eficiência usando a API Bulk e aprenda a lidar com falhas parciais. 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 “Indexação em massa e a API Bulk”?

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

  1. Indexando documentos no Elasticsearch
  2. Operações CRUD com documentos
  3. Mapeamento básico e tipos de dados
  4. Indexação em massa e a API Bulk
← Voltar para Elasticsearch & Full Text Search Systems