Course: Data Science and Database Technologies
Source: ElasticSearch, Data Base and Data Mining Group (DBMG, Politecnico di Torino), local path 20-ElasticSearch_v2.pdf, 68 PDF pages. No individual lecturer name is printed on the slides. Lecture number 20 follows the supplied filename identifier.
Lecture summary
ElasticSearch (ES) is a real-time, distributed, horizontally scalable search and analytics engine built on Apache Lucene, exposing a RESTful JSON/HTTP API and replicating transaction logs across nodes to avoid data loss. Mapping SQL concepts roughly (database → cluster, table → index, row → document, column → field), ES uses the term index in three ways: as a collection of documents (noun), as inserting/replacing a document (verb), and as an inverted index (mapping every unique word to the list of documents containing it). Full-text fields pass through a 3-stage Analyzer (character filters → tokenizers → token filters such as lowercasing, stemming, stopwords, and synonyms)—requiring the exact same analyzer on both indexed text and queries—while Query DSL distinguishes fast boolean filters on exact values from relevance-scoring queries (match, compound bool with must, should, must_not). Because ES documents are immutable, updates reindex a modified copy and schedule the old version for background cleanup.
To rank full-text hits by _score (default top 10, optionally refined via rescoring), ElasticSearch combines a fast Boolean match, TF/IDF term weights (, , and field-length norm ), and the Vector Space Model (VSM) using Cosine similarity. Because pure lexical matching ignores semantic meaning (such as "nice german teacher" matching “holidays to Nice”), modern search adds fixed-size dense semantic embeddings (e.g., BERT, OpenAI Embeddings, CLIP) built independently of user queries and combines sparse lexical scores with dense semantic scores via Hybrid Search.
For horizontal scalability and concurrency, each ES index is split into shards (each a full Lucene index whose writes flush every 1 second into immutable Lucene segments) distributed and replicated across cluster nodes. Updates always hit the primary shard first and replicate to replica shards in parallel, where out-of-order arrivals are resolved—and optimistic concurrency control is supported—using each document’s monotonically incrementing _version field.
Learning route
- Revisit prerequisite context: MongoDB Polyglot Persistence Hadoop and Apache Spark and Similarity Dissimilarity and Correlation.
- Read ElasticSearch Data Model Inverted Index Analyzers and Query DSL for SQL-to-ES mapping, the 3 meanings of
index, analyzers, Filter vs. Query, Query DSL (match,bool), and immutable CRUD. - Read ElasticSearch TF-IDF Vector Space Model Semantic Embeddings and Hybrid Search for
_score, TF/IDF + field-length norm formulas, VSM cosine similarity (happy hippopotamus), lexical vs. semantic embeddings (BERT/CLIP, Iliad example), and Hybrid Search. - Read ElasticSearch Sharding Clusters and Optimistic Concurrency Control for sharding, 1-second Lucene segments, clusters, primary-first parallel replication, and
_versionoptimistic concurrency control.
Source map
| PDF pages | Material |
|---|---|
| 1–6 | Search overview, ElasticSearch capabilities, real-world examples (GitHub, Wikipedia, StackOverflow), Lucene foundation, RESTful JSON API, and replicated transaction logs |
| 7–13 | Data representation: SQL → ES mapping (cluster, index, document, field), 3 overloaded meanings of index, inverted index, and (Index, Id) identity |
| 14–25 | Exact values ([Hard]) vs. full text ([Soft]), dynamic mapping, inverted index, Analyzer pipeline (char filter → tokenizer → token filter), and Filter vs. Query |
| 26–33 | Query DSL over HTTP POST, match query, compound bool query (must, should, must_not), multi-index queries, and ES 7.0 index-type deprecation |
| 34–38 | Immutable CRUD: PUT insert (optional ID), 4-step update reindexing (_update), and DELETE with background cleanup |
| 39–52 | Results scoring: _score, rescoring, Boolean + TF/IDF + field-length norm formulas, Vector Space Model, Cosine similarity, and "happy hippopotamus" VSM example |
| 53–59 | Lexical limitations ("nice german teacher"), semantic embeddings (BERT, OpenAI, CLIP), VSM vs. BERT (Iliad example), dense preprocessing, and Hybrid Search |
| 60–68 | Horizontal scalability (shards, 1-second Lucene segments, clusters) and document versioning (optimistic concurrency control, parallel out-of-order replication, _version) |
Worked examples from the source
1. Compound bool Query DSL on departments (Slides 30–31)
Finds developers named John or Mark (should with minimum_should_match: 1) excluding Smith (must_not), combining _score across matching must/should clauses.
2. Vector Space Model "happy hippopotamus" (Slides 51–52)
Query vector (happy common = 2, hippopotamus rare = 5) compared against D1 (“I am happy in summer”, ), D2 (“After Christmas I’m a hippopotamus”, ), and D3 (“The happy hippopotamus helped Harry”, ): D3 aligns at (highest _score), and D2 beats D1 because its angle to is smaller due to "hippopotamus" having higher IDF weight.
3. Lexical search failure & Iliad comparison (Slides 53, 57)
Querying "nice german teacher" returns documents about “holidays to Nice” and “german shepherd”; similarly, VSM on “Proemio dell’Iliade, lite tra Achille e Agamennone” vs. “Cantami o diva del Pelide Achille l’Ira funesta” only sees "Achille" ([0,0,0,8,0,0]), whereas a 769-feature BERT embedding captures their shared meaning independently of the query.
Revision prompts
- Distinguish the three meanings of
indexin ElasticSearch and trace how a document flows through a 3-stage Analyzer. - Explain why
Filteris faster thanQuery, when to use each, and howboolmapsmust,should, andmust_not. - Explain why ElasticSearch documents are immutable and trace the four internal steps of an
_update. - Write the TF, IDF, and field-length norm formulas, and explain why
D2outranksD1in the"happy hippopotamus"VSM example. - Contrast VSM lexical vectors against dense semantic embeddings (BERT/CLIP), and explain how Hybrid Search combines them.
- Explain what happens inside a shard every 1 second, and why
_versionis required even when the primary shard is always written first.
Source and scope
Data Base and Data Mining Group (DBMG, Politecnico di Torino), ElasticSearch, local path 20-ElasticSearch_v2.pdf, 68 PDF pages. This note paraphrases and organizes the source material; added study examples in the linked concept notes are labeled explicitly.