การสร้างดัชนีจำนวนมากและ Bulk API
สร้างดัชนีเอกสารหลายพันรายการอย่างมีประสิทธิภาพด้วย Bulk API และเรียนรู้การจัดการความล้มเหลวบางส่วน
การสร้างดัชนีจำนวนมากและ Bulk API เป็นบทเรียน Elasticsearch & Full Text Search Systems ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Elasticsearch & Full Text Search Systems และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Elasticsearch & Full Text Search Systems มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
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.
เรียนรู้ Elasticsearch & Full Text Search Systems ด้วย AI tutor — ฟรี
เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป
- คอร์ส
- 12
- บทเรียน
- 48
คำถามที่พบบ่อย
บทเรียน “การสร้างดัชนีจำนวนมากและ Bulk API” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การสร้างดัชนีจำนวนมากและ Bulk API” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Elasticsearch & Full Text Search Systems ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Elasticsearch & Full Text Search Systems มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การสร้างดัชนีจำนวนมากและ Bulk API”
สร้างดัชนีเอกสารหลายพันรายการอย่างมีประสิทธิภาพด้วย Bulk API และเรียนรู้การจัดการความล้มเหลวบางส่วน คุณปฏิบัติ Elasticsearch & Full Text Search Systems ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Elasticsearch & Full Text Search Systems หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Elasticsearch & Full Text Search Systems บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “การสร้างดัชนีจำนวนมากและ Bulk API” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Elasticsearch & Full Text Search Systems นี้ได้ไหม
ได้ บทเรียน Elasticsearch & Full Text Search Systems ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การทำดัชนีเอกสารใน Elasticsearch
- การดำเนินการ CRUD กับเอกสาร
- การแมปและประเภทข้อมูลพื้นฐาน
- การสร้างดัชนีจำนวนมากและ Bulk API