What Is Elasticsearch? β Definition and How It Works
Learn what Elasticsearch is, how inverted indexes and analysis work, how relevance scoring behaves, and where it fits against a database.
Elasticsearch is a distributed search and analytics engine built on Lucene. It indexes documents so they can be searched by text relevance rather than only by exact field values.
1. The Inverted Index
Rather than storing documents and scanning them, it stores a map from each term to the documents containing it.
"proxy" β [doc1, doc4, doc9]
"residential" β [doc4, doc7]
A query for both terms intersects the lists, which is why full-text search over millions of documents returns in milliseconds.
2. Analysis Decides What Is Searchable
Text is processed before indexing: split into tokens, lowercased, stemmed, and filtered. The same analysis applies to queries, so both sides match.
That step defines what can be found. An analyser that does not stem will not match "running" to "run"; one that strips punctuation will not match a part number containing hyphens.
3. Relevance Scoring
Results are ranked, not merely filtered. Scoring weighs how often a term appears in a document against how common it is across the corpus, adjusted for document length.
Rare terms therefore contribute more than common ones β which is the behaviour that makes text search feel intelligent, and the reason results are ordered rather than arbitrary.
4. Distribution
An index is divided into shards spread across nodes, with replicas for redundancy. Queries fan out and results are merged.
Shard count is fixed at index creation and is the decision people most often regret: too few limits parallelism, too many adds overhead per query.
5. Where It Fits
| Need | Elasticsearch | A relational database |
|---|---|---|
| Full-text relevance ranking | Yes | Limited |
| Aggregations over large sets | Strong | Depends |
| Transactions | No | Yes |
| Joins | Limited | Native |
| Source of truth | Not advisable | Yes |
The common architecture keeps authoritative data in a database and indexes a projection of it for search.
6. Why It Is Not a Source of Truth
It is eventually consistent, has no transactions, and reindexing is a routine operation that assumes the data exists elsewhere.
Treating it as primary storage works until a mapping change requires a reindex and there is nothing to reindex from.
7. Practical Notes
- Mappings matter. Field types are largely fixed once set; changing them means reindexing.
- Text and keyword are different. Text is analysed for search; keyword is exact, for filtering and aggregation. Most fields need both.
- Deep pagination is expensive. Use a scroll or search-after cursor for large exports.
- Bulk indexing is far faster than one document at a time.
8. Summary
Elasticsearch indexes documents into an inverted index, analyses text so queries and content match, and ranks results by relevance across a distributed cluster.
It excels at text search and aggregations, lacks transactions and joins, and should be treated as a derived index over authoritative data held elsewhere.