Search Engines: Elasticsearch and OpenSearch

Run a dedicated search cluster for relevance-tuned search, facets and log analytics.

Advanced · about 8 hours · difficulty 4/5

Learn first: Full-Text Search Fundamentals

Elasticsearch and its open-source fork OpenSearch are distributed search and analytics engines built on Apache Lucene. They power site search, e-commerce catalogs, and log analytics stacks. Apache Solr, also built on Lucene, is the older sibling still common in enterprise search.

Core concepts

  • An index holds JSON documents; it is split into shards spread across nodes, each with replicas for availability.
  • A mapping defines field types. text fields are analyzed for search, keyword fields are exact values for filters, sorting and aggregations. Getting mappings right up front matters because changing them usually means reindexing.
  • Analyzers control tokenization, stemming, synonyms and language handling.

Querying

The Query DSL combines full-text queries (match, multi_match) with filters (term, range) inside a bool query. Filters do not affect scoring and are cached. Aggregations power facets ("Brand: Apple (42)") and analytics.

Operating it

  • It is not a primary database. Keep the source of truth elsewhere and feed the index through a sync job, queue or change-data-capture.
  • Use aliases so you can build a new index and switch traffic to it with zero downtime.
  • Watch heap usage, shard count (too many small shards is a common mistake) and cluster health.

Managed offerings (Elastic Cloud, Amazon OpenSearch Service) remove much of the ops burden.

Pitfalls

  • Relying on dynamic mapping, which guesses types and can break later.
  • Deep pagination with from and size; use search_after instead.

You are ready to move on when you can index a product catalog with explicit mappings, return faceted results with filters, and reindex behind an alias without downtime.

Key concepts

  • Indexes, shards and replicas
  • Mappings: text vs keyword
  • Analyzers and synonyms
  • Bool queries and filters
  • Aggregations and facets
  • Index aliases and reindexing
  • Apache Solr: Lucene-based alternative common in enterprise

Mini project

Sync a product table into OpenSearch, build a search API with facets for brand and price range, and perform a zero-downtime reindex using an alias.

Check yourself

Why should a product brand be mapped as keyword rather than text if you want to show it as a facet?

Free resources