Skip to the workspace
Pebellslearn by building
Introduction to Elasticsearch  ›  Lesson

Search Engines vs Relational Databases

Search Engines vs Relational DBs 12 minA relational database answers which rows exactly match, while a search engine like Elasticsearch answers which documents match best and ranks them.

elasticsearch / Search Engines vs Relational Databases

Explore each scene at your own pace.

01 · The rule

The rule

Search Engines vs Relational Databases

A shopper types "gardning for busy" into the bookshop's search box. A relational database with WHERE title = 'gardning for busy' finds nothing — the spelling is wrong and the words are incomplete. A search engine is built for exactly this: finding the most relevant matches, ranked, even when the question is messy.

The rule

A database answers "which rows match?"; a search engine answers "which match best?"

A relational database such as PostgreSQL is built around exact truth. Tables have a fixed schema, rows are linked by keys, and transactions guarantee that a payment and its order are saved together or not at all. A query either matches a row or it does not.

Elasticsearch is a search engine built on the Lucene library. It stores JSON documents and, when it saves text, it breaks it into words (lower-cased, split on spaces and punctuation) and records which documents contain each word. A search then scores every candidate document for relevance and returns them best first.

Question Relational DB Elasticsearch
Unit of data Row in a table JSON document in an index
Text search LIKE '%garden%', slow, no ranking Word lookup, fast, ranked by relevance
Transactions across records Yes No
Joins Yes Very limited
New data visible Immediately after commit After a refresh, about 1 second

That last row matters: Elasticsearch is near real-time. A newly indexed book becomes searchable after the next refresh, which happens every second by default.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.