Indexación masiva y Bulk API
Indexe miles de documentos de forma eficiente mediante Bulk API y aprenda a gestionar los fallos parciales.
Indexación masiva y Bulk API 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.
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 replacecreate— fail if the id existsupdate— partial updatedelete— 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.
Aprende Elasticsearch & Full Text Search Systems con un tutor de IA — gratis
Escribe y ejecuta código real en tu navegador, obtén ayuda instantánea de un tutor de IA disponible 24/7 y continúa donde lo dejaste en la web o en la aplicación.
- Cursos
- 12
- Lecciones
- 48
Preguntas frecuentes
¿La lección «Indexación masiva y Bulk API» es gratis?
Sí — el texto completo de «Indexación masiva y Bulk API» 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 «Indexación masiva y Bulk API»?
Indexe miles de documentos de forma eficiente mediante Bulk API y aprenda a gestionar los fallos parciales. 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 «Indexación masiva y Bulk API»?
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
- Indexación de documentos en Elasticsearch
- Operaciones CRUD con documentos
- Mapeos básicos y tipos de datos
- Indexación masiva y Bulk API