Elasticsearch & Lucene (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What is an Inverted Index and why is it so fast for text search?
senior LevelMost AskedCode ExampleelasticsearchBasic
In Simple Words: Traditional databases index documents to words (Document -> Words). An Inverted Index inverts this relationship (Word -> List of Documents):
- It splits document text into individual vocabulary terms, standardizes them, and maintains a sorted list of every document ID where each term appears (called a Posting List).
- Searching for words becomes an instantaneous O(1) dictionary lookup, followed by intersecting or unioning document ID lists!
text
Inverted Index Diagram:
Term Posting List (Document IDs & Frequencies)
"kubernetes" -> [Doc 1 (tf: 2), Doc 4 (tf: 1)]
"docker" -> [Doc 1 (tf: 1), Doc 2 (tf: 3), Doc 3 (tf: 1)]
"ingress" -> [Doc 2 (tf: 1), Doc 4 (tf: 2)]