Elasticsearch & Full Text Search Systems · Lezione

Profilazione e slow query log

Diagnostichi i problemi di prestazioni profilando le singole query e registrando le operazioni lente nello slow log, così potrà individuare e risolvere i veri colli di bottiglia.

Lezione 4 di 413 passaggi

Profilazione e slow query log è una lezione Elasticsearch & Full Text Search Systems gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Elasticsearch & Full Text Search Systems, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Elasticsearch & Full Text Search Systems include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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.
Gratis per iniziare

Impara Elasticsearch & Full Text Search Systems con un tutor IA — gratis

Scrivi ed esegui vero codice nel tuo browser, ricevi aiuto istantaneo da un tutor IA disponibile 24/7, e riprendi da dove hai lasciato sul web o nell'app.

Corsi
12
Lezioni
48

Domande Frequenti

La lezione «Profilazione e slow query log» è gratuita?

Sì — il testo completo di «Profilazione e slow query log» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Elasticsearch & Full Text Search Systems, passa a CoddyKit PRO. Il corso Elasticsearch & Full Text Search Systems include 4 lezioni in totale.

Cosa imparerò in «Profilazione e slow query log»?

Diagnostichi i problemi di prestazioni profilando le singole query e registrando le operazioni lente nello slow log, così potrà individuare e risolvere i veri colli di bottiglia. Eserciti Elasticsearch & Full Text Search Systems con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Elasticsearch & Full Text Search Systems?

Non è richiesta alcuna esperienza precedente. Elasticsearch & Full Text Search Systems su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Profilazione e slow query log»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Elasticsearch & Full Text Search Systems?

Sì. Ogni lezione Elasticsearch & Full Text Search Systems include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Strategie di ottimizzazione delle query
  2. Best practice per le prestazioni di indicizzazione
  3. Caching e concorrenza
  4. Profilazione e slow query log
← Torna a Elasticsearch & Full Text Search Systems