Elasticsearch & Full Text Search Systems · 课时

性能分析与慢查询日志

通过分析单个查询并使用慢日志记录慢操作来诊断性能问题,从而找到并修复真正的瓶颈。

第 4 / 4 课13 个步骤

性能分析与慢查询日志 是 CoddyKit 上的免费 Elasticsearch & Full Text Search Systems 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 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_time for 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.
免费开始

用 AI 导师学习 Elasticsearch & Full Text Search Systems — 免费

在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。

课程
12
课程
48

常见问题解答

「性能分析与慢查询日志」课时是免费的吗?

是的 — 「性能分析与慢查询日志」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Elasticsearch & Full Text Search Systems 课程的其余内容,请升级到 CoddyKit PRO。 Elasticsearch & Full Text Search Systems 课程共包含 4 节课。

「性能分析与慢查询日志」这节课中我会学到什么?

通过分析单个查询并使用慢日志记录慢操作来诊断性能问题,从而找到并修复真正的瓶颈。 你通过在浏览器中直接运行的动手代码来练习 Elasticsearch & Full Text Search Systems,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Elasticsearch & Full Text Search Systems 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Elasticsearch & Full Text Search Systems 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。

「性能分析与慢查询日志」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Elasticsearch & Full Text Search Systems 课中编写并运行代码吗?

能。每节 Elasticsearch & Full Text Search Systems 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 查询优化策略
  2. 索引性能最佳实践
  3. 缓存与并发
  4. 性能分析与慢查询日志
← 返回 Elasticsearch & Full Text Search Systems