プロファイリングとスロークエリログ
個々のクエリをプロファイリングし、slow logで遅い処理を記録して、実際のボトルネックを特定・解消する方法を学びます。
「プロファイリングとスロークエリログ」はCoddyKit上の無料Elasticsearch & Full Text Search Systemsレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応の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_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.
よくある質問
「プロファイリングとスロークエリログ」レッスンは無料ですか?
はい。「プロファイリングとスロークエリログ」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Elasticsearch & Full Text Search Systemsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Elasticsearch & Full Text Search Systemsコースには全4レッスンが含まれています。
「プロファイリングとスロークエリログ」で何を学びますか?
個々のクエリをプロファイリングし、slow logで遅い処理を記録して、実際のボトルネックを特定・解消する方法を学びます。 ブラウザで直接実行するハンズオンコードでElasticsearch & Full Text Search Systemsを演習し、24時間対応の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フィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- クエリ最適化戦略
- インデックス作成のベストプラクティス
- キャッシュと同時実行制御
- プロファイリングとスロークエリログ