Search Systems (Elasticsearch, Inverted Index)

Why Not Just SQL LIKE?

-- This is SLOW on large tables (full scan, no index):
SELECT * FROM products WHERE name LIKE "%wireless headphone%";

Full-text search engines use inverted indexes: map every word to the documents containing it.

Inverted Index

Documents: doc1: "wireless bluetooth headphone" doc2: "wired headphone with mic" doc3: "wireless mouse" Inverted Index: "wireless" → [doc1, doc3] "bluetooth" → [doc1] "headphone" → [doc1, doc2] "wired" → [doc2] "mouse" → [doc3] "mic" → [doc2] Query "wireless headphone" → intersection of [doc1,doc3] ∩ [doc1,doc2] = [doc1]

Elasticsearch Architecture

When to Use

Key Takeaways