Inverted index explained in plain terms means understanding how a search engine finds every document containing a word without reading them all. The central question is how a search over millions of pages can answer in milliseconds, and the answer is an index built backwards: instead of listing the words in each document, it lists the documents for each word.
An inverted index is a data structure that maps each term to the list of documents in which it appears, together with where it appears and how often. It is the core of every full-text search engine, from web search to the search box inside a single application.
The idea is simple: pay the cost of building the map once, and every search becomes a lookup. This article explains what an inverted index is, how it works, and where it is used.
Key takeaways
- An inverted index maps each word to the documents that contain it.
- It turns a search over millions of documents into a simple lookup.
- Each entry, called a posting list, records where a word appears.
- It powers web search, site search, and log analysis alike.
- Building it costs time and space, but searching it is almost instant.
What an inverted index is
An inverted index has two parts: a dictionary of terms and, for each term, a posting list of the documents that contain it. The dictionary is kept sorted so a term can be found quickly, and the posting list holds document identifiers, often with the positions of the term inside each document and how many times it appears.
The word inverted describes the reversal of the natural order. A document lists its words in the order they appear, but a search needs the opposite: given a word, which documents contain it. The index answers that question directly, without touching any document that does not match.
The index is built by tokenising every document, breaking its text into words, normalising them by lowercasing and stemming, and then recording each word against the document it came from. Stop words such as “the” and “and” are usually dropped, since they appear everywhere and add nothing to a search. Our guide to Elasticsearch explains a search engine built on inverted indexes, and our guide to data mining explains the wider field in which text indexes are used.
How an inverted index works
Indexing starts with tokenisation. Each document is split into terms, each term is normalised to a standard form, and the indexer records a posting for every term in every document. The postings are then sorted and merged, so that each term has one list, ordered by document.
Searching a single term is a dictionary lookup followed by reading its posting list. The result is the set of documents containing the term, and the positions in the list let the engine rank documents by how often the term appears and where it appears.
Multi-word queries combine posting lists. An AND query intersects the lists, keeping only documents in all of them, while an OR query merges them, and a phrase query checks that the positions line up in order. Because the lists are sorted, these operations are fast even for very common words.
Ranking decides the order of results. The engine scores each document by term frequency, how rare the term is across the collection, and where the term appears, so that a document in which the word appears in the title outranks one in which it appears once in passing. The classic scoring formula is TF-IDF, and modern engines use BM25, a refinement of the same idea.
Updating an index is the hard part. An inverted index is built for reading, not for changing, so most engines write new documents to a small fresh segment and merge segments in the background, rather than editing the main index in place. This is why a document can take a moment to become searchable after it is added.

Comparing an inverted index with other search methods
An inverted index is one of several ways to search text, and each was built with a different emphasis. Scanning every document works for tiny collections, a suffix tree finds substrings fast, and a forward index suits analytics, but each approach trades speed for flexibility in a different way.
The table below sets out the main contrasts between the leading approaches.
| Aspect | Inverted index | Full scan | Forward index |
|---|---|---|---|
| How it searches | Looks up a term’s posting list | Reads every document | Lists terms per document |
| Speed | Milliseconds, however large the data | Slow, grows with the data | Fast for one document |
| Multi-word queries | Intersects sorted posting lists | Checks each document | Slow, must scan terms |
| Update cost | Needs segment merging | Free, nothing to update | Cheap, append a document |
| Best for | Full-text search at scale | Tiny collections | Analytics on one document |
The practical result is that an inverted index is the right choice for search at any real scale, a full scan suits only the smallest collections, and a forward index fits analytics that read one document at a time.
Where inverted indexes are used
Web search engines are the largest inverted indexes in existence. Google, Bing, and their peers keep an index of the web’s pages, and a query is answered by looking up its terms and intersecting their posting lists, which is why a search over billions of pages returns in a fraction of a second.
Site search uses the same idea at a smaller scale. A shop, a documentation site, or a news archive builds an inverted index of its own pages, so visitors can find products or articles by keyword without waiting for a database scan.
Log analysis tools index machine-generated text. Splunk and the Elastic Stack build inverted indexes over logs, so an engineer can search millions of log lines for an error message and see the matching entries instantly.
Email and document systems index their contents. A mailbox search, a legal discovery tool, and a code search engine all rely on inverted indexes to find messages and files by the words inside them.
Databases with full-text search build inverted indexes alongside their tables. PostgreSQL, MySQL, and MongoDB all offer text indexes, which let an application search free text with the same database that stores the data.
Strengths and limits
The greatest strength of an inverted index is its speed. Once built, a search costs a lookup and a walk down a posting list, and the cost barely grows as the collection grows, which is why search feels instant even at web scale.
It is also a strength that the index supports rich queries. Boolean combinations, phrases, prefixes, and fuzzy matches are all operations on posting lists, so one structure serves many kinds of search.
The limits are real, though. The index can be as large as the text it indexes, updates are expensive because the structure is built for reading, and it cannot answer questions that are not about words, such as finding images by content. For those, other indexes are needed.
Inverted index checklist
- Use an inverted index whenever users search free text at any scale.
- Tokenise consistently; the index and the query must normalise words the same way.
- Drop stop words and stem carefully, or the index grows without helping.
- Store term positions if phrase search matters to your users.
- Rank with BM25 rather than plain term counts for better results.
- Merge index segments in the background so new documents become searchable.
- Test with real queries; a rare-word query behaves very differently from a common one.
- Watch index size; it can rival the size of the text itself.
- Add a forward index too if you also need analytics on single documents.
Frequently asked questions
What is an inverted index in simple terms?
It is a map from each word to the list of documents that contain it, so a search becomes a lookup instead of a scan.
Why is it called inverted?
Because it reverses the natural order: documents list their words, but the index lists, for each word, the documents that contain it.
What is a posting list?
It is the list of documents in which a term appears, usually with the term’s positions and frequency inside each document.
How do search engines handle several words at once?
By intersecting or merging the posting lists of the words, and checking term positions for phrase queries.
What is TF-IDF?
It is a scoring method that weighs how often a term appears in a document against how rare it is across the whole collection, so distinctive words count for more.
When should I not use an inverted index?
When the collection is tiny, when the data changes constantly, or when the search is not about words at all.
The bottom line
Inverted index explained in one line is this: map every word to the documents that contain it, and search becomes a lookup.
It is the structure behind every search box that answers instantly, and the reason a query over billions of pages takes milliseconds.
This article is general information about how inverted indexes work, not advice about building search for a particular system.







