Site Search With Contentstack and Algolia

Search is how impatient visitors navigate

Contentstack's APIs are built for delivery, not full-text search. For search-as-you-type, typo tolerance, and facets, pair it with a search engine like Algolia (or Elastic, Coveo, Typesense).

Architecture

Editor publishes → Contentstack webhook / Automate → Indexer function → Algolia index → Search UI

Designing Records

Index what users search, not the whole entry:

{
  "objectID": "blt123-en-us",
  "title": "Getting started with JSM",
  "summary": "Queues, SLAs and request types...",
  "url": "/blog/jsm-getting-started",
  "type": "blog_post",
  "topics": ["Atlassian", "ITSM"],
  "locale": "en-us",
  "published_at": 1763600000
}

Split long articles into multiple records (one per section) for better relevance.

Indexing on Publish

// Serverless function triggered by a publish webhook
export default async function handler(req, res) {
  const { data } = req.body;
  const entry = data.entry;
  await index.saveObject(toRecord(entry, data.locale));
  res.status(200).end();
}

Handle unpublish and delete events to remove records.

Relevance

  • Searchable attributes in priority order: title, summary, body
  • Custom ranking by popularity or recency
  • Synonyms for domain terms

Frontend

Use InstantSearch libraries for React, Vue, or vanilla JS: search box, hits, facets, pagination.

Security

Use a search-only API key in the browser and validate webhook requests on the server.

Keep the CMS as the source of truth and the search index as a fast, disposable view of it.

Arivanandhan Chitheshwaran