What is an inverted index in Elasticsearch?

Answer

An inverted index is the core data structure that makes fast full-text search possible. Instead of storing documents and scanning them one by one, an inverted index maps each unique term (word) to the list of documents that contain it. For example, the term "elasticsearch" might map to document IDs [1, 5, 12]. When you search for "elasticsearch", Elasticsearch looks up the term in the inverted index and instantly retrieves the matching document IDs — rather than scanning all documents. Each shard in Elasticsearch contains a Lucene index, which is essentially a collection of inverted indexes (one per field).