AI Hints
Home›Elasticsearch Tutorial›What Is Elasticsearch
Elasticsearch · Lesson 2 of 120

Why Not SQL LIKE

The search box problem.

⏱ 2 min read▶ Video at 1:02🎓 Free
Watch this lesson in the Elasticsearch courseWatch on YouTube ↗Full Elasticsearch course

You've just joined Trailhead Outdoors, an online shop for hiking and camping gear. Their search box uses a database query with LIKE. Customers keep saying, search finds nothing.

  • Trailhead Outdoors
  • Search uses LIKE
  • Customers find nothing

Here's the old search, in SQL. A customer types waterproof jackets. LIKE looks for that exact text, in that exact order. Jackets, plural, doesn't match jacket. So the shop shows zero results.

old_search.sqlsql
SELECT name
FROM products
WHERE name LIKE '%waterproof jackets%';

-- (0 rows)

LIKE vs a search engine

LIKE matches exact text, and can't tell which result is best. It scans every row, so it gets slow. A search engine understands words, plurals and typos. It ranks results, and stays fast at any size.

SQL LIKE

  • Exact text onlyNo rankingScans every row

Search engine

  • Words, plurals, typosBest match firstFast at any size

Summary

LIKE matches exact text, has no ranking, and gets slow. A search engine understands words and ranks results. Next, the trick that makes it fast.

Key takeaways
  • Exact text
  • No ranking
  • Slow scans
Next up: The Inverted Index — the index at the back of a book