Building a Product Catalog with Node, Express, and Elasticsearch
A hands-on tutorial showing how to model a product catalog for search, facets, and fast retrieval using Node.js, Express, and Elasticsearch — perfect for JavaScript storefronts.
Building a Product Catalog with Node, Express, and Elasticsearch
Search is core to any product catalog. Buyers expect relevant results, facets for filtering, and near-instantaneous responses. In this tutorial, we'll design and implement a scalable product catalog using Node.js, Express, and Elasticsearch, focusing on schema design, indexing strategy, and query patterns suitable for JavaScript storefronts.
High-level design
We will:
- Model a product document optimized for search and faceting.
- Set up an indexing pipeline with incremental updates.
- Implement search endpoints with result ranking, suggestions, and facets.
1. Product schema
A typical product document in Elasticsearch might include:
{
"id": "sku-1234",
"title": "Responsive Card UI Kit",
"description": "A suite of accessible, responsive card components for React.",
"price": 49.00,
"categories": ["UI components", "React"],
"tags": ["card", "responsive", "a11y"],
"vendor": "Acme Components",
"rating": 4.7,
"available": true,
"updatedAt": "2025-12-01T12:00:00Z"
}
Use analyzed fields for full-text search (title, description) and keyword fields for aggregations (categories, tags, vendor).
2. Index mapping
Carefully define mappings to optimize query speed and memory usage. Example mapping highlights:
- Use
textwith akeywordsub-field for titles to support both full-text search and exact match filtering. - Enable
normscarefully; disable for large fields where scoring should be controlled by other signals. - Use
completionor search-as-you-type analyzers for suggestions.
3. Indexing pipeline
Accept product updates from your CMS or seller portal and push changes to Elasticsearch. For high-traffic shops, prefer incremental updates to reduce reindexing. Use a message queue (Kafka, RabbitMQ) or serverless events to process updates asynchronously and maintain eventual consistency.
4. Search endpoint with Node & Express
Example express endpoint structure:
app.get('/search', async (req, res) => {
const { q, page = 1, size = 20, categories, minPrice, maxPrice } = req.query;
const esQuery = buildEsQuery({ q, categories, minPrice, maxPrice, page, size });
const result = await esClient.search(esQuery);
res.json(formatResponse(result));
});
Key features to include:
- Multi-field matching with boosted fields (title > description).
- Filter context for facets (categories, price ranges) to allow fast caching.
- Function score to boost recent products or sponsored listings.
5. Faceting and aggregations
Use aggregations to compute counts for categories, tags, and price ranges. Remember that aggregations can be heavy; limit cardinality and consider pre-computed counts for high-cardinality fields.
6. Suggestions and typo tolerance
Provide search-as-you-type by using edge_ngram analyzers or the completion suggester. For typo tolerance, enable fuzzy matching with care — fuzzy results can be expensive, so prefer a staged approach: exact matches first, then fuzzy as a fallback.
7. Caching and performance
Cache common queries at the CDN or application layer. Use warmers or query caches for hot categories during promotional events. Monitor query latencies and reject or slow down unusually expensive queries with circuit breakers.
8. Relevance tuning
Relevance is part art, part science. Use A/B testing and human review to tune scoring. Signals that matter include text matches, vendor reputation, recency, and conversion history.
"Fast, relevant search with well-designed facets will make your catalog feel smaller and easier to buy from — improving conversions more than any shiny frontend feature."
9. Monitoring and metrics
Track search KPIs: query latency, zero-result rate, CTR (click-through-rate), and conversions by query. Use these metrics to identify synonyms and missing content.
10. Security and access control
Protect administrative APIs and indexing pipelines. Use role-based access, signed tokens for search requests that need personalization, and rate-limiting for public endpoints.
With an index modeled for both relevance and analytics, and an API optimized for filters and caching, your product catalog can serve both shoppers and internal analytics reliably. Start with a simple mapping, iterate relevance with real traffic, and build tooling that makes it easy for sellers to keep their product data fresh.
Related Topics
Maya Chen
Product Architect
Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.
Up Next
More stories handpicked for you