Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
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.

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.

The shortcut

Ask one question about the feature: does it need correctness or relevance? Money, stock counts and user accounts need correctness — keep them in the relational database as the source of truth. Search boxes, log exploration and "similar items" need relevance — copy the data into Elasticsearch and search there.

Designing the bookshopStep 1 of 4
  1. Orders and payments

    They must never be half-saved or lost. Correctness → relational database.

The trap is treating Elasticsearch as your only database. It can store documents safely, but it has no multi-document transactions, so it is a poor home for data where two changes must succeed together.

Drills

Answer fast — trust the rule.

quick drill

A shopper searches "quiet gardens". Which system can naturally return "The Quiet Garden" ranked first?

quick drill

Which job is the best fit for a relational database rather than Elasticsearch?

quick drill

You index a new book and search for it immediately, but it is missing. Then, a second later, it appears. Why?

quick drill

What does Elasticsearch store as its basic unit of data?

Remember

  • A database answers "which rows match?"; a search engine answers "which match best?"
  • Correctness → relational database; relevance → Elasticsearch.
  • Elasticsearch is near real-time and has no multi-document transactions.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWhere does each part live?

A bookshop needs a search box, a shopping cart with payments, and a stock count per book. Explain which parts belong in a relational database, which belong in Elasticsearch, and how the two stay in step.