Skip to content
Ameen Abozaid
MID-043

Search systems

  • 6 Lessons
  • 2.5 h practice (estimate)
On this page 8 topics

Overview

Topics

  • Full-text search
  • inverted indexes
  • Elasticsearch/OpenSearch basics

Learn first

2.5 h of practice (estimate)

Learning outcomes

  1. Explain inverted indexes, analyzers, tokenization, and relevance scoring.
  2. Index documents and run full-text, filtered, and faceted queries in OpenSearch/Elasticsearch.
  3. Keep a search index in sync with the source of truth via events.
  4. Compare PostgreSQL full-text search with a dedicated engine.

Lessons

  1. 01How search engines find things
  2. 02Analyzers and relevance
  3. 03Queries, filters, and facets
  4. 04Keeping the index in sync
  5. 05PostgreSQL full-text vs a search engine
  6. 06Demo: product search with typo tolerance and facets

Lab and exercises

Lab

MID-043-LAB1 · Shop search

Outcomes: 1–4 · Time: ~2.5 h Build a search service: an OpenSearch index fed by ProductUpdated events, with typo tolerance and category and price facets. Write a runbook for reindexing from scratch (new index, bulk load, alias switch). Add a short note comparing PostgreSQL full-text with this setup for Shop. Acceptance: reindex from scratch documented; search never becomes the source of truth.

Exercises (assessment: lab plus tool-choice scenario)

IDOutcomeTask
MID-043-EX011Build the inverted index for three short product names and answer the query "red shoe".
MID-043-EX021Explain what changes if the analyzer lowercases and stems, using the text "Running Shoes".
MID-043-EX032Write a query: text search for "wireless headphones", category filter, price at most 200, and a category facet.
MID-043-EX043Describe an event flow that keeps the index in sync and explain how deletions and out-of-order events are handled.
MID-043-EX054Tool choice: a 5 000-product shop wants simple name search; another has 5 million with facets and typo tolerance. Choose for each.
Show solutions
  • EX01 red → {1,3}; shoe → {1,2,3} (assuming docs 1 and 3 contain "red"); result docs 1 and 3.
  • EX02 Tokens become run, shoe; queries "run" and "SHOE" match. Danger: unrelated words sharing a stem can match.
  • EX03 bool with must: match name, filter: [term category, range price lte 200], and aggs.terms on category (keyword).
  • EX04 Outbox → broker → indexer upserts by product id; ProductDeleted deletes the document; use the product version as external version so older events are ignored.
  • EX05 5 000 products with simple search: PostgreSQL full-text (no extra system). 5 million with facets and fuzziness: dedicated engine.

Outcome 3 is also covered by the lab (events feed the index; reindex documented).

Quiz

Outcomes: O1 inverted index and relevance · O2 queries and facets · O3 keeping the index in sync · O4 PostgreSQL vs engine.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1An inverted index maps:O1
  2. 2An analyzer typically does:O1
  3. 3Stemming helps match:O1
  4. 4Filters in a bool query are:O2
  5. 5Facets show:O2
  6. 6Typo tolerance in a match query uses:O2
  7. 7Best way to sync products to the index:O3
  8. 8To reindex from scratch with little downtime:O3
  9. 9An advantage of PostgreSQL full-text:O4
  10. 10A reason to adopt a dedicated engine:O4

Practical part

Lab MID-043-LAB1 plus a tool-choice scenario (MID-043-EX05). Pass: quiz at least 8/10, lab with documented reindex and no dual writes, and justified tool choices.

Common mistakes

Dual writes to database and index; using search as primary storage.

Assessment

Lab plus tool-choice scenario.

Career relevance

Data platform integration (SRB-007).

Type to search levels, phases, modules and lessons.