Elasticsearch

Elasticsearch is a distributed search and analytics engine built on Apache Lucene. It excels at full-text search with relevance ranking, autocomplete, and fast aggregations over huge volumes of documents — the engine behind product search bars and log dashboards everywhere.

It's a complement to your primary database, not a replacement. Elasticsearch is where you index data for searching; your transactional database remains the source of truth. Treating it as the system of record is the classic mistake.

TL;DR

Quick Example

Index a document, then run a full-text query that ranks by relevance:

Core Concepts

Data Modeling

Operational Best Practices

Common Mistakes

Letting dynamic mapping explode

Treating Elasticsearch as the source of truth

FAQ

When should I use Elasticsearch?

When you need rich full-text search (relevance ranking, fuzzy matching, autocomplete) or fast aggregations/analytics over large document or log volumes. For transactional, relational data, use a database like PostgreSQL — Elasticsearch sits alongside it for search.

Can Elasticsearch be my primary database?

It's not designed to be. It lacks the transactional guarantees and consistency model of a primary database, and its near-real-time indexing can briefly lag. Keep your source of truth in a transactional store and index into Elasticsearch.

What's the difference between text and keyword fields?

text fields are analyzed (tokenized, lowercased) for full-text search — great for matching within prose. keyword fields are stored verbatim for exact matches, filtering, sorting, and aggregations. Many fields are mapped as both.

Elasticsearch or OpenSearch?

OpenSearch is the Apache-2.0 fork created after Elasticsearch's license change. They're closely related and both production-grade; choose based on licensing preferences, managed-service availability (AWS offers OpenSearch), and the specific features you need.

Related Topics

References