CalcSnippets Search
Search 3 min read

Elasticsearch Index Design for Search Performance

Design Elasticsearch indexes with mappings, analyzers, shards, replicas, aliases, refresh intervals, query patterns, and operational reliability.

Search performance starts before the first query

Elasticsearch can make product search feel fast and flexible, but good results depend on index design. Mappings, analyzers, shard count, refresh settings, document shape, and query patterns all affect speed and relevance. Treating Elasticsearch like a JSON dumping ground usually creates problems later.

Start with what users need to find. Product names, support articles, logs, locations, profiles, and catalog items all require different analyzers and ranking choices. The index should reflect search behavior, not only the shape of the source database.

Mappings and analyzers define meaning

A mapping tells Elasticsearch how to store and search each field. A text field may be analyzed for full-text search, while a keyword field is better for exact filters, sorting, and aggregations. Many fields need both forms. For example, a product title may need full-text matching and exact keyword sorting.

Analyzers control tokenization, lowercasing, stemming, synonyms, and language behavior. Global products may need different analyzers for different languages or fields. A search experience that works in English may fail badly for names, accents, compound words, or languages with different tokenization rules.

  • Use keyword fields for exact filters and aggregations.
  • Use text fields with appropriate analyzers for full-text search.
  • Avoid dynamic mapping surprises in important indexes.
  • Test relevance with real queries, not only synthetic examples.

Shard count is an operational decision

Too few shards can limit scale. Too many shards waste resources and make clusters harder to operate. Shard planning should consider index size, growth, query load, hardware, retention, and rollover strategy. Logs and time-series data often benefit from index lifecycle management, while product catalogs may use aliases for zero-downtime reindexing.

Replicas improve availability and read capacity, but they also use resources. Refresh intervals affect how quickly new documents become searchable. Near-real-time search is useful, but forcing extremely frequent refreshes can hurt indexing throughput. Choose settings based on user needs, not assumptions.

Design for reindexing

Mappings cannot always be changed in place. Sooner or later, teams need to create a new index and reindex data. Aliases make this practical by allowing the application to point to a stable name while the backing index changes. A clean reindex process is essential for schema changes, analyzer improvements, and large migrations.

Relevance tuning should also be repeatable. Keep representative query sets, expected results, and business rules so ranking changes can be reviewed. Search quality is a product feature, not just infrastructure.

Monitor both speed and relevance

Track query latency, indexing latency, failed searches, shard health, heap pressure, disk watermarks, and slow queries. Also track zero-result searches, low-click queries, and popular filters. Search performance is not only milliseconds. It is whether users find what they came for quickly and confidently.

Separate search tuning from source data storage

Elasticsearch indexes should be shaped for search, not forced to mirror database tables exactly. It is normal to denormalize fields, add searchable labels, store display text, and prepare ranking signals during indexing. Keep the source of truth elsewhere, then build the search document around the questions users actually ask.

Keep reading

Related guides