Elasticsearch & Full Text Search Systems · บทเรียน

แนวทางปฏิบัติที่ดีด้านประสิทธิภาพการทำดัชนี

นำแนวทางปฏิบัติที่ดีมาใช้กับการทำดัชนีข้อมูล เช่น การทำดัชนีแบบกลุ่ม ช่วงเวลาการรีเฟรช และการรวมเซกเมนต์ เพื่อเพิ่มความเร็วในการรับข้อมูล

บทเรียน 2 จาก 411 ขั้นตอน

แนวทางปฏิบัติที่ดีด้านประสิทธิภาพการทำดัชนี เป็นบทเรียน Elasticsearch & Full Text Search Systems ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Elasticsearch & Full Text Search Systems และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Elasticsearch & Full Text Search Systems มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Boosting Indexing Speed

Why is indexing performance crucial? It's about efficiently adding data to Elasticsearch. Fast indexing means your data is searchable sooner and your cluster resources are used effectively.

This lesson will show you how to speed things up!

How Indexing Works

When you index a document, Elasticsearch doesn't just store it. It goes through a process:

  • Analysis: Text fields are broken down into terms.
  • Storage: Document is added to Lucene segments.
  • Refresh: Segments are made searchable.
  • Flush: Segments are written to disk.

Each step has performance implications.

Single Docs: A Performance Bottleneck

Indexing documents one by one means a separate network request and processing overhead for each. Imagine sending thousands of individual letters instead of one large package.

This approach is fine for occasional updates, but for large datasets, it's very inefficient and slow.

Speed Up with Bulk Indexing

Bulk indexing allows you to send multiple index, update, or delete operations in a single API request.

This drastically reduces network round trips and overhead, making data ingestion much faster. It's the go-to method for loading large amounts of data.

Your First Bulk Request

The bulk API uses a special format: action_and_metadata followed by the document_body. Each pair must be on its own line.

Try indexing two documents in one go:

POST /_bulk
{"index": {"_index": "products", "_id": "1"}}
{"name": "Laptop Pro X", "price": 1200}
{"index": {"_index": "products", "_id": "2"}}
{"name": "Wireless Mouse", "price": 25}

Refresh Intervals: Searchability vs. Speed

When a document is indexed, it's not immediately searchable. Elasticsearch periodically "refreshes" an index, making newly indexed documents visible for search.

  • Frequent refreshes: Documents become searchable faster, but consume more resources (CPU, I/O).
  • Less frequent refreshes: Slower searchability, but better indexing performance.

The default refresh interval is 1 second.

Optimize Refresh for Bulk Loads

For large bulk indexing operations, you can temporarily disable refreshes or increase the interval. Remember to set it back afterwards!

Disable refreshes:

PUT /my_index/_settings
{
  "index": {
    "refresh_interval": "-1"
  }
}

Lucene Segments & Merging

Elasticsearch stores data in Lucene segments. Each refresh creates new segments. Too many small segments can degrade query performance.

Elasticsearch automatically merges smaller segments into larger ones in the background. This process is resource-intensive but crucial for query speed.

When to Force Merge

For indices that are no longer being written to (read-only), you can explicitly trigger a force merge to consolidate segments into a single segment (or a few larger ones).

This can significantly improve search performance, but it's a heavy operation and should only be done on static indices.

POST /my_static_index/_forcemerge?max_num_segments=1

Indexing Best Practices Check

You're about to ingest 1 million new documents into an Elasticsearch index. Which of the following strategies would best improve the indexing speed?

Recap: Faster Indexing

Great job! You've learned key strategies to optimize Elasticsearch indexing performance:

  • Use the Bulk API for large data loads.
  • Adjust refresh intervals (e.g., disable/increase) during bulk indexing.
  • Understand segment merging and consider _forcemerge for static indices.

These practices ensure your data is ingested quickly and efficiently!

เริ่มต้นได้ฟรี

เรียนรู้ Elasticsearch & Full Text Search Systems ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

คำถามที่พบบ่อย

บทเรียน “แนวทางปฏิบัติที่ดีด้านประสิทธิภาพการทำดัชนี” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “แนวทางปฏิบัติที่ดีด้านประสิทธิภาพการทำดัชนี” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Elasticsearch & Full Text Search Systems ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Elasticsearch & Full Text Search Systems มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “แนวทางปฏิบัติที่ดีด้านประสิทธิภาพการทำดัชนี”

นำแนวทางปฏิบัติที่ดีมาใช้กับการทำดัชนีข้อมูล เช่น การทำดัชนีแบบกลุ่ม ช่วงเวลาการรีเฟรช และการรวมเซกเมนต์ เพื่อเพิ่มความเร็วในการรับข้อมูล คุณปฏิบัติ Elasticsearch & Full Text Search Systems ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Elasticsearch & Full Text Search Systems หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Elasticsearch & Full Text Search Systems บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “แนวทางปฏิบัติที่ดีด้านประสิทธิภาพการทำดัชนี” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Elasticsearch & Full Text Search Systems นี้ได้ไหม

ได้ บทเรียน Elasticsearch & Full Text Search Systems ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. กลยุทธ์การปรับประสิทธิภาพคำค้น
  2. แนวทางปฏิบัติที่ดีด้านประสิทธิภาพการทำดัชนี
  3. การแคชและการทำงานพร้อมกัน
  4. การทำโปรไฟล์และบันทึกการสืบค้นที่ช้า
← กลับไปที่ Elasticsearch & Full Text Search Systems