# Search Engines: Elasticsearch and OpenSearch

> Run a dedicated search cluster for relevance-tuned search, facets and log analytics. Free notes, key concepts, resources and a mini project.

Canonical: https://www.internhack.in/roadmaps/tracks/backend/elasticsearch-opensearch
Last updated: 2026-11-28

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](https://www.internhack.in/roadmaps/tracks/backend/full-text-search-basics)

**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

- [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html) (Elastic)
- [OpenSearch documentation](https://opensearch.org/docs/latest/) (OpenSearch)
- [Apache Solr Reference Guide](https://solr.apache.org/guide/) (Apache)

Previous: [Full-Text Search Fundamentals](https://www.internhack.in/roadmaps/tracks/backend/full-text-search-basics) · Next: [Connection Pooling](https://www.internhack.in/roadmaps/tracks/backend/connection-pooling)

## More in Beyond Relational: NoSQL and Search

- [NoSQL Families and When to Use Them](https://www.internhack.in/roadmaps/tracks/backend/nosql-fundamentals)
- [Document Databases with MongoDB](https://www.internhack.in/roadmaps/tracks/backend/mongodb)
- [Key-Value Stores and DynamoDB](https://www.internhack.in/roadmaps/tracks/backend/key-value-dynamodb)
- [Wide-Column Stores: Cassandra and ScyllaDB](https://www.internhack.in/roadmaps/tracks/backend/cassandra-wide-column)
- [Graph Databases with Neo4j](https://www.internhack.in/roadmaps/tracks/backend/graph-databases)
- [Time-Series Databases](https://www.internhack.in/roadmaps/tracks/backend/time-series-databases)
- [Full-Text Search Fundamentals](https://www.internhack.in/roadmaps/tracks/backend/full-text-search-basics)
- [Search Engines: Elasticsearch and OpenSearch](https://www.internhack.in/roadmaps/tracks/backend/elasticsearch-opensearch)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Backend Developer Roadmap](https://www.internhack.in/roadmaps/tracks/backend)
