Aggregazioni per la ricerca a faccette
Utilizzi le aggregazioni di Elasticsearch per creare faccette, istogrammi e metriche riepilogative insieme ai risultati della ricerca.
Aggregazioni per la ricerca a faccette è 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.
Beyond Matching
Search finds documents; aggregations summarize them. They power faceted navigation, dashboards, and analytics, all in the same request as the search.
Two Families
Aggregations come in two main families:
- Bucket aggregations group documents (e.g. by category)
- Metric aggregations compute numbers (e.g. average price)
A Terms Facet
The terms aggregation produces a bucket per distinct value with counts, the classic facet.
GET /products/_search
{ "size": 0, "aggs": {
"by_category": { "terms": { "field": "category" } }
}}size 0 Trick
Setting size: 0 returns no document hits, only the aggregation results, which is efficient when you only want the facets.
Aggregate on keyword
Aggregations run on non-analyzed fields. Use the keyword field, not the analyzed text field, or you will bucket on individual tokens.
{ "terms": { "field": "brand.keyword" } }Metric Aggregations
Metrics like avg, min, max, and sum compute a single value over matching documents.
"aggs": { "avg_price": { "avg": { "field": "price" } } }Histograms
A histogram buckets numeric values into fixed intervals, great for price ranges.
"aggs": { "price_ranges": {
"histogram": { "field": "price", "interval": 100 }
}}Date Histograms
A date_histogram groups by calendar intervals like day or month, ideal for time-series charts.
"aggs": { "per_day": { "date_histogram": {
"field": "created", "calendar_interval": "day"
}}}Nesting Aggregations
You can nest a metric inside a bucket: average price within each category. Nesting is how rich facets are built.
"aggs": { "by_cat": {
"terms": { "field": "category" },
"aggs": { "avg_price": { "avg": { "field": "price" } } }
}}Facets Respect the Query
Aggregations are computed over the documents that match the query and filters, so facet counts naturally reflect the current search context.
Cardinality for Distinct Counts
The cardinality metric gives an approximate distinct-value count, far cheaper than exact counting on large data.
"aggs": { "unique_brands": {
"cardinality": { "field": "brand.keyword" } } }Quick Check
Why aggregate on a keyword field instead of a text field?
Recap
You learned aggregations for faceted search: bucket aggregations like terms and histograms, metric aggregations like avg and cardinality, nesting metrics inside buckets, the size: 0 trick, and why facets use keyword fields.
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 «Aggregazioni per la ricerca a faccette» è gratuita?
Sì — il testo completo di «Aggregazioni per la ricerca a faccette» è 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 «Aggregazioni per la ricerca a faccette»?
Utilizzi le aggregazioni di Elasticsearch per creare faccette, istogrammi e metriche riepilogative insieme ai risultati della ricerca. 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 «Aggregazioni per la ricerca a faccette»?
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
- Ricerche per frase e prossimità
- Query fuzzy e wildcard
- Evidenziazione dei risultati di ricerca
- Aggregazioni per la ricerca a faccette