การทำโปรไฟล์และบันทึกการสืบค้นที่ช้า
วินิจฉัยปัญหาประสิทธิภาพด้วยการทำโปรไฟล์การสืบค้นแต่ละรายการและบันทึกการทำงานที่ช้าด้วยบันทึกการทำงานช้า เพื่อค้นหาและแก้ไขคอขวดที่แท้จริง
การทำโปรไฟล์และบันทึกการสืบค้นที่ช้า เป็นบทเรียน Elasticsearch & Full Text Search Systems ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Elasticsearch & Full Text Search Systems และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Elasticsearch & Full Text Search Systems มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Measure Before You Optimize
Guessing at performance fixes wastes time. Elasticsearch gives you two precise tools: the Profile API for dissecting a single query, and slow logs for catching expensive operations in production.
The Profile API
Add "profile": true to any search request. Elasticsearch returns a detailed timing breakdown of how the query executed on each shard.
GET my_index/_search
{
"profile": true,
"query": { "match": { "title": "elasticsearch" } }
}Reading Query Timings
The profile output lists each Lucene query and the time spent in phases like build_scorer, next_doc, and score. A surprisingly slow phase points you straight to the culprit.
Rewrite Time
Watch the rewrite_time. Wildcard, prefix, and range queries can rewrite into thousands of terms, inflating this number. If rewrite dominates, reconsider the query type or use a keyword/edge-ngram field.
Profiling Aggregations
The profile output also has an aggregations section. It shows initialize, collect, and build_aggregation times, helping you spot a costly high-cardinality terms aggregation.
Profile API Caveats
Profiling adds overhead and does not capture network or coordination time. Use it for relative comparison between query versions, not as an absolute production latency figure.
The Search Slow Log
The slow log records queries that exceed configurable time thresholds, per shard. It separates the query phase from the fetch phase and uses warn/info/debug/trace levels.
PUT my_index/_settings
{
"index.search.slowlog.threshold.query.warn": "1s",
"index.search.slowlog.threshold.fetch.warn": "500ms"
}The Indexing Slow Log
A parallel indexing slow log catches documents that take too long to index, useful for spotting expensive pipelines or oversized documents.
PUT my_index/_settings
{
"index.indexing.slowlog.threshold.index.warn": "1s"
}Per-Shard Logging
Slow log thresholds apply per shard, not per request. A query slow on one shard but fast overall will still be logged for that shard, helping you find a single hot or unbalanced shard.
Acting on Findings
Once you identify a slow pattern, common fixes are: add a filter to narrow the dataset, replace heavy wildcard queries, increase shard count for hot indices, or pre-aggregate data. Always re-profile to confirm the gain.
A Workflow
Production loop: slow log surfaces a bad query, you reproduce it with the Profile API, identify the costly phase, apply a fix, and verify. This data-driven cycle beats guesswork every time.
Quick Check
Test your understanding of performance diagnostics.
Recap
You learned to diagnose performance:
- The Profile API breaks down query and aggregation timings phase by phase.
- Watch
rewrite_timefor expanding wildcard/range queries. - Search and indexing slow logs catch expensive operations per shard in production.
- Follow a measure-fix-verify loop instead of guessing.
เรียนรู้ 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 ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “การทำโปรไฟล์และบันทึกการสืบค้นที่ช้า” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Elasticsearch & Full Text Search Systems นี้ได้ไหม
ได้ บทเรียน Elasticsearch & Full Text Search Systems ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- กลยุทธ์การปรับประสิทธิภาพคำค้น
- แนวทางปฏิบัติที่ดีด้านประสิทธิภาพการทำดัชนี
- การแคชและการทำงานพร้อมกัน
- การทำโปรไฟล์และบันทึกการสืบค้นที่ช้า