Inverted IndexAnalyzersTokenizersStemmingN-gramsMappingsText vs KeywordBM25

Inverted Index & Text Analysis

The foundation of everything in Elasticsearch — how text is broken into tokens, stored in an inverted index, and matched at query time.

40 min read9 sections
01

Why Traditional DBs Fail at Search

When you run SELECT * FROM products WHERE name LIKE '%running shoes%', the database performs a — checking every row sequentially. There's no index to help. It can't . It won't match "run shoe" or "shoes for running." This is fundamentally the wrong data structure for search.

AspectSQL LIKEElasticsearch
PerformanceFull table scan — O(N)Inverted index lookup — O(1) to O(log N)
Relevance rankingNone — results are unorderedBM25 scoring — best matches first
Fuzzy matchingNot supportedEdit distance, phonetic, stemming
Partial word matchOnly with leading % (kills index)N-grams, edge n-grams, prefix queries
SynonymsNot supportedBuilt-in synonym token filter
ScalabilitySingle node, single tableDistributed across shards and nodes
📚

The Library Card Catalog

SQL LIKE is like walking through every shelf in a library checking each book's title. An inverted index is like the card catalog — you look up 'running' and instantly get a list of every book containing that word, sorted by relevance. The catalog is built once (at index time) so lookups are instant.

🔑 ES is a Secondary Index

Elasticsearch is NOT a primary database. It has no transactions, no referential integrity, and is . The canonical pattern: write to your primary DB (), then sync to ES for search. ES is a .

1 / 9