Elasticsearch & Full Text Search Systems · Lezione

Indicizzazione in blocco e Bulk API

Indicizzi migliaia di documenti in modo efficiente usando la Bulk API e impari a gestire gli errori parziali.

Lezione 4 di 413 passaggi

Indicizzazione in blocco e Bulk API è 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.

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.

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 «Indicizzazione in blocco e Bulk API» è gratuita?

Sì — il testo completo di «Indicizzazione in blocco e Bulk API» è 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 «Indicizzazione in blocco e Bulk API»?

Indicizzi migliaia di documenti in modo efficiente usando la Bulk API e impari a gestire gli errori parziali. 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 «Indicizzazione in blocco e Bulk API»?

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. Indicizzazione dei documenti in Elasticsearch
  2. Operazioni CRUD sui documenti
  3. Mapping e tipi di dati di base
  4. Indicizzazione in blocco e Bulk API
← Torna a Elasticsearch & Full Text Search Systems