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

The Inverted Index

The index at the back of a book.

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

Think of a thick book. To find every page about tents, you don't read the whole book. You turn to the index at the back. Tents, pages twelve and forty. Elasticsearch works the same way.

  • Don't read every page
  • Use the index
  • Jump straight there

Words to documents

When you add documents, Elasticsearch splits the text into words, called terms. For each term, it keeps a list of the documents that contain it. That list is the inverted index. Searching for tent just looks up one row.

TermDocuments
tent1, 2, 3
waterproof1, 14, 22
jacket14, 15, 16
warm8, 15

A search, step by step

You search for waterproof jacket. Elasticsearch splits your search into terms. It looks up each term in the inverted index. It combines the document lists. And it ranks them, so document fourteen, which has both words, comes first.

  1. waterproof jacket
  2. Split into terms
  3. Look up each term
  4. Combine the lists
  5. Rank: doc 14 first

Summary

An inverted index maps each word to the documents that contain it, so search is a quick lookup, not a scan. Next, documents and indexes.

Key takeaways
  • Terms
  • Document lists
  • Lookup, not scan
Next up: Documents and Indexes — JSON in, JSON out