Syncs Payload collections to an Algolia index, turning each document into a lean text record without per-collection code. It hooks into collection saves, unpublishes and deletes, handles drafts and autosaves, and pushes index settings from config on every reindex. Requires Payload 3.39.0 or newer and Algolia credentials; a headless React entry offers search hooks and highlight components.
Algolia search sync for Payload with draft-aware indexing, a best-effort text extractor that turns any collection into search records with zero per-collection code, admin reindex buttons, and index settings managed as code.
Installation
npm i @whatworks/payload-algolia-search16
Stars
1
Forks
2
Open Issues
3 days ago
Last Updated
39
Weekly Downloads
v0.2.0
npm Version
193.1 KB
Unpacked Size
1
Dependencies
16+1 since Sep 6
| Date | Stars |
|---|---|
| Dec 5, 2026 | 16 |
| Dec 4, 2026 | 16 |
| Dec 3, 2026 | 16 |
| Dec 2, 2026 | 16 |
| Dec 1, 2026 | 16 |
| Nov 30, 2026 | 16 |
| Nov 29, 2026 | 16 |
| Nov 28, 2026 | 16 |
| Nov 27, 2026 | 16 |
| Nov 26, 2026 | 16 |
| Nov 25, 2026 | 16 |
| Nov 24, 2026 | 16 |
| Nov 23, 2026 | 16 |
| Nov 22, 2026 | 16 |
| Nov 21, 2026 | 16 |
| Nov 20, 2026 | 16 |
| Nov 19, 2026 | 16 |
| Nov 18, 2026 | 16 |
| Nov 17, 2026 | 15 |
| Nov 16, 2026 | 15 |
| Nov 15, 2026 | 15 |
| Nov 14, 2026 | 15 |
| Nov 13, 2026 | 15 |
| Nov 12, 2026 | 15 |
| Nov 11, 2026 | 15 |
| Nov 10, 2026 | 15 |
| Nov 9, 2026 | 15 |
| Nov 8, 2026 | 15 |
| Nov 7, 2026 | 15 |
| Nov 6, 2026 | 15 |
| Nov 5, 2026 | 15 |
| Nov 4, 2026 | 15 |
| Nov 3, 2026 | 15 |
| Nov 2, 2026 | 15 |
| Nov 1, 2026 | 15 |
| Oct 31, 2026 | 15 |
| Oct 30, 2026 | 15 |
| Oct 29, 2026 | 15 |
| Oct 28, 2026 | 15 |
| Oct 27, 2026 | 15 |
| Oct 26, 2026 | 15 |
| Oct 25, 2026 | 15 |
| Oct 24, 2026 | 15 |
| Oct 23, 2026 | 15 |
| Oct 22, 2026 | 15 |
| Oct 21, 2026 | 15 |
| Oct 20, 2026 | 15 |
| Oct 19, 2026 | 15 |
| Oct 18, 2026 | 15 |
| Oct 17, 2026 | 15 |
| Oct 16, 2026 | 15 |
| Oct 15, 2026 | 15 |
| Oct 14, 2026 | 15 |
| Oct 13, 2026 | 15 |
| Oct 12, 2026 | 15 |
| Oct 11, 2026 | 15 |
| Oct 10, 2026 | 15 |
| Oct 9, 2026 | 15 |
| Oct 8, 2026 | 15 |
| Oct 7, 2026 | 15 |
| Oct 6, 2026 | 15 |
| Oct 5, 2026 | 15 |
| Oct 4, 2026 | 15 |
| Oct 3, 2026 | 15 |
| Oct 2, 2026 | 15 |
| Oct 1, 2026 | 15 |
| Sep 30, 2026 | 15 |
| Sep 29, 2026 | 15 |
| Sep 28, 2026 | 15 |
| Sep 27, 2026 | 15 |
| Sep 26, 2026 | 15 |
| Sep 25, 2026 | 15 |
| Sep 24, 2026 | 15 |
| Sep 23, 2026 | 15 |
| Sep 22, 2026 | 15 |
| Sep 21, 2026 | 15 |
| Sep 20, 2026 | 15 |
| Sep 19, 2026 | 15 |
| Sep 18, 2026 | 15 |
| Sep 17, 2026 | 15 |
| Sep 16, 2026 | 15 |
| Sep 15, 2026 | 15 |
| Sep 14, 2026 | 15 |
| Sep 13, 2026 | 15 |
| Sep 12, 2026 | 15 |
| Sep 11, 2026 | 15 |
| Sep 10, 2026 | 15 |
| Sep 9, 2026 | 15 |
| Sep 8, 2026 | 15 |
| Sep 7, 2026 | 15 |
| Sep 6, 2026 | 15 |
Shared by 12 plugins in what-works-global/payload-packages.
38+29 since Sep 6
| Date | Weekly downloads |
|---|---|
| Dec 5, 2026 | 38 |
| Dec 4, 2026 | 33 |
| Dec 3, 2026 | 25 |
| Dec 2, 2026 | 25 |
| Dec 1, 2026 | 32 |
| Nov 30, 2026 | 31 |
| Nov 29, 2026 | 30 |
| Nov 28, 2026 | 27 |
| Nov 27, 2026 | 35 |
| Nov 26, 2026 | 30 |
| Nov 25, 2026 | 38 |
| Nov 24, 2026 | 31 |
| Nov 23, 2026 | 31 |
| Nov 22, 2026 | 36 |
| Nov 21, 2026 | 35 |
| Nov 20, 2026 | 26 |
| Nov 19, 2026 | 27 |
| Nov 18, 2026 | 19 |
| Nov 17, 2026 | 19 |
| Nov 16, 2026 | 20 |
| Nov 15, 2026 | 29 |
| Nov 14, 2026 | 35 |
| Nov 13, 2026 | 47 |
| Nov 12, 2026 | 60 |
| Nov 11, 2026 | 59 |
| Nov 10, 2026 | 61 |
| Nov 9, 2026 | 62 |
| Nov 8, 2026 | 47 |
| Nov 7, 2026 | 41 |
| Nov 6, 2026 | 32 |
| Nov 5, 2026 | 19 |
| Nov 4, 2026 | 36 |
| Nov 3, 2026 | 33 |
| Nov 2, 2026 | 30 |
| Nov 1, 2026 | 29 |
| Oct 31, 2026 | 29 |
| Oct 30, 2026 | 26 |
| Oct 29, 2026 | 20 |
| Oct 28, 2026 | 2 |
| Oct 27, 2026 | 2 |
| Oct 26, 2026 | 3 |
| Oct 25, 2026 | 4 |
| Oct 24, 2026 | 3 |
| Oct 23, 2026 | 2 |
| Oct 22, 2026 | 6 |
| Oct 21, 2026 | 6 |
| Oct 20, 2026 | 6 |
| Oct 19, 2026 | 6 |
| Oct 18, 2026 | 5 |
| Oct 17, 2026 | 6 |
| Oct 16, 2026 | 6 |
| Oct 15, 2026 | 2 |
| Oct 14, 2026 | 2 |
| Oct 13, 2026 | 4 |
| Oct 12, 2026 | 3 |
| Oct 11, 2026 | 4 |
| Oct 10, 2026 | 4 |
| Oct 9, 2026 | 6 |
| Oct 8, 2026 | 10 |
| Oct 7, 2026 | 15 |
| Oct 6, 2026 | 13 |
| Oct 5, 2026 | 13 |
| Oct 4, 2026 | 15 |
| Oct 3, 2026 | 16 |
| Oct 2, 2026 | 14 |
| Oct 1, 2026 | 12 |
| Sep 30, 2026 | 7 |
| Sep 29, 2026 | 9 |
| Sep 28, 2026 | 9 |
| Sep 27, 2026 | 6 |
| Sep 26, 2026 | 8 |
| Sep 25, 2026 | 8 |
| Sep 24, 2026 | 6 |
| Sep 23, 2026 | 11 |
| Sep 22, 2026 | 10 |
| Sep 21, 2026 | 12 |
| Sep 20, 2026 | 13 |
| Sep 19, 2026 | 11 |
| Sep 18, 2026 | 13 |
| Sep 17, 2026 | 13 |
| Sep 16, 2026 | 11 |
| Sep 15, 2026 | 10 |
| Sep 14, 2026 | 8 |
| Sep 13, 2026 | 7 |
| Sep 12, 2026 | 6 |
| Sep 11, 2026 | 5 |
| Sep 10, 2026 | 5 |
| Sep 9, 2026 | 2 |
| Sep 8, 2026 | 3 |
| Sep 7, 2026 | 4 |
| Sep 6, 2026 | 9 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1064440892-algolia-search)<a href="https://payloaddirectory.dev/plugins/1064440892-algolia-search"><img src="https://payloaddirectory.dev/badge/1064440892-algolia-search.svg" alt="Payload Directory"></a>README
Algolia search sync for Payload with defaults that hold up in production: draft-aware indexing, a best-effort text extractor that turns any collection into lean search records with zero per-collection code, admin reindex buttons, and index settings managed as code.
text, textarea, and richText value — through tabs, groups, rows, collapsibles, arrays, and blocks — into a single content attribute, in document order. Add a block with a text field and it's searchable the moment an editor saves. title, path, and breadcrumbs come along automatically.autosave intervals in the hundreds of milliseconds.runAlgoliaReindex(payload) for scripts and cron. Full reindexes are atomic (replaceAllObjects) — search keeps working mid-rebuild and stale records are pruned.searchableAttributes, snippeting, and faceting are pushed to Algolia on every reindex, so relevance config is reviewable and reproducible instead of hand-edited in the dashboard./react entry ships useAlgoliaSearch (debounced search-as-you-type, typed to the record shape), useHitCursor (keyboard navigation), useInsights (click/conversion analytics), and dependency-free <Highlight>/<Snippet> components — a complete quick-search UI without react-instantsearch, with zero styling imposed.

pnpm add @whatworks/payload-algolia-search
Requires Payload 3.39.0+ — earlier versions don't pass the request to admin header actions, so the reindex icon's access gate would silently hide it for everyone.
import { algoliaSearchPlugin } from '@whatworks/payload-algolia-search'
import { buildConfig } from 'payload'
export default buildConfig({
// ...
plugins: [
algoliaSearchPlugin({
algolia: {
appId: process.env.ALGOLIA_APP_ID || '',
apiKey: process.env.ALGOLIA_ADMIN_API_KEY || '', // admin key — server-side only
index: process.env.ALGOLIA_INDEX || '',
},
collections: {
pages: true,
news: true,
},
getPath: ({ collection, doc }) => getPath(collection.slug, doc),
}),
],
})
Then regenerate the import map so the admin panel can resolve the reindex header action:
payload generate:importmap
Missing credentials don't crash the boot: the plugin logs a warning and pauses sync, while hooks, endpoint, and admin components stay registered so the generated import map is identical across environments.
Every document becomes one lean, text-only record:
{
"objectID": "news:6a45d3f153222a49f8454d1f", // <collection>:<id> — collision-proof across collections
"collection": "news",
"title": "Weather info",
"path": "/news/weather-info",
"breadcrumbs": ["Learn More", "Weather info"], // only when the doc has a trail
"content": "…all indexable text, compressed, in document order…",
}
title — the collection's useAsTitle field (falls back to doc.title).path — your getPath result, falling back to the last breadcrumb's url (nested-docs stores the full path there).breadcrumbs — nested-docs labels, only when there's more than one (ancestors + own title).content — the best-effort extraction, capped at contentLimit (default 4000 chars) to stay well under Algolia's record size limit.The matching default index settings (pushed on every reindex):
{
searchableAttributes: ['title', 'breadcrumbs', 'content'], // order = ranking priority
attributesToHighlight: ['title', 'breadcrumbs'],
attributesToSnippet: ['content:20'],
attributesForFaceting: ['filterOnly(collection)'],
snippetEllipsisText: '…',
}
With react-instantsearch this gives you title highlighting and a match-centred content excerpt (<Snippet attribute="content" hit={hit} />) with no extra work.
For the common quick-search case you don't need react-instantsearch at all — the /react entry is a headless layer typed to the record shape above, built on the Algolia lite client the package already depends on:
'use client'
import {
Highlight,
Snippet,
useAlgoliaSearch,
useHitCursor,
useInsights,
} from '@whatworks/payload-algolia-search/react'
import Link from 'next/link'
import { useRouter } from 'next/navigation'
const appId = process.env.NEXT_PUBLIC_ALGOLIA_APP_ID ?? ''
const indexName = process.env.NEXT_PUBLIC_ALGOLIA_INDEX ?? ''
const searchApiKey = process.env.NEXT_PUBLIC_ALGOLIA_SEARCH_KEY ?? '' // search-only key — never the admin key
export const Search: React.FC = () => {
const router = useRouter()
const { query, setQuery, hits } = useAlgoliaSearch({
appId,
clickAnalytics: true, // stamp __queryID/__position so clicks are attributable
indexName,
searchApiKey,
})
const { sendClick } = useInsights({ appId, indexName, searchApiKey })
const { activeItemRef, cursor, onKeyDown, setCursor } = useHitCursor(hits, {
onSelect: (hit) => {
if (hit.path) {
sendClick(hit)
router.push(hit.path)
}
},
})
return (
<div>
<input value={query} onChange={(e) => setQuery(e.target.value)} onKeyDown={onKeyDown} />
{hits.map((hit) => (
<Link
data-active={hit.objectID === cursor || undefined}
href={hit.path ?? ''}
key={hit.objectID}
onClick={() => sendClick(hit)}
onMouseEnter={() => setCursor(hit.objectID)}
ref={hit.objectID === cursor ? activeItemRef : undefined}
>
<Highlight attribute="title" hit={hit} />
{hit.breadcrumbs && <div>{hit.breadcrumbs.join(' / ')}</div>}
<Snippet attribute="content" hit={hit} />
</Link>
))}
</div>
)
}
useAlgoliaSearch — debounced search-as-you-type: typed hits, out-of-order responses dropped, no request for an empty query. Options: filters (e.g. 'collection:news'), hitsPerPage, debounceMs, enabled (pause while a modal is closed), clickAnalytics (see useInsights), and raw searchParams. Extra attributes added by a record transform are typed via the generic: useAlgoliaSearch<SearchHit & { section: string }>({ … }).useHitCursor — wrap-around ArrowUp/ArrowDown keyboard cursor, Enter-to-select, and an activeItemRef that keeps the active hit scrolled into view (attach it to the active element only, as above).useInsights — Algolia Insights click/conversion tracking, built on the official search-insights client (an optional peer dependency, loaded lazily the first time the hook runs, so it stays out of bundles that never track — install it only in apps that call useInsights). Returns sendClick(hit) / sendConversion(hit); attach onClick={() => sendClick(hit)} to each result. Combine with useAlgoliaSearch({ clickAnalytics: true }) so hits carry the __queryID/__position that make clicks clickedObjectIDsAfterSearch. search-insights manages the anonymous cookie token (override with a logged-in id via userToken); enabled gates loading and sending on consent.<Highlight> / <Snippet> — render _highlightResult/_snippetResult as React nodes, matches wrapped in <mark> — no dangerouslySetInnerHTML. Style via className/highlightedTag; array attributes like breadcrumbs are joined with separator. Snippeting content works out of the box because the plugin's default index settings request it.Everything is unstyled — the components render a single <span> and you own all surrounding markup. If you need facets or pagination, reach for react-instantsearch instead; the records and index settings work with it as-is.
Global and per-collection exclude lists. By default these field names are skipped at any depth: slug, meta (the SEO plugin's group), metadata, breadcrumbs, filename, mimeType, url, thumbnailURL, apiKey — plus each collection's useAsTitle field, which is indexed separately as title. Entries match a field name at any depth ('internalNotes') or a dot-path from the document root ('hero.eyebrow').
import { algoliaSearchPlugin, defaultExcludeFields } from '@whatworks/payload-algolia-search'
algoliaSearchPlugin({
// ...
excludeFields: [...defaultExcludeFields, 'legalDisclaimer'], // global (replaces the default list)
collections: {
pages: true,
news: {
excludeFields: ['slug', 'excerpt'], // replaces the effective list for news only
},
},
})
Field-level flags beat every list. On any field:
{
name: 'internalNotes',
type: 'textarea',
custom: { algoliaSearch: false }, // never indexed
},
{
name: 'region',
type: 'select', // non-text types are skipped by default…
custom: { algoliaSearch: true }, // …unless opted in (value is stringified)
options: [...],
}
Per-collection record shaping. The record transform receives the default record and the doc — typed from your generated Payload types for that collection. Return undefined to keep the default, a record to index (spread defaultRecord to extend), or null to keep the doc out of the index entirely — existing records are removed, so a hideFromSearch checkbox works retroactively:
collections: {
pages: {
record: ({ defaultRecord, doc }) => {
if (doc.hideFromSearch) return null
return { ...defaultRecord, section: doc.section }
},
},
},
Rich text. Lexical states go through the official convertLexicalToPlaintext when @payloadcms/richtext-lexical is installed (it's an optional peer). Pass richTextConverters to teach it custom nodes (e.g. blocks inside rich text), or replace extraction entirely with richTextToText: (value) => string. Without the package, a dependency-free extractor collects text nodes from Lexical and Slate states alike, including stringified ones.
Admin header action — an icon next to the other header controls opens the reindex modal: rebuild everything atomically, reindex one collection at a time, and see per-collection record counts as runs finish. Hide it for everyone with reindex.button: false.
Endpoint — POST /api/algolia-search/reindex (all collections, atomic) or POST /api/algolia-search/reindex?collection=pages. Default access: any authenticated user; override with reindex.access, which both guards the endpoint and decides whether a given user sees the header icon.
Programmatic — from a script, migration, or cron job:
import { runAlgoliaReindex } from '@whatworks/payload-algolia-search'
const result = await runAlgoliaReindex(payload) // or (payload, { collection: 'pages' })
// { indexed: { pages: 42, news: 128 }, mode: 'all', total: 170 }
Only published documents are fetched for drafts-enabled collections; trashed documents are skipped.
algoliaSearchPlugin({
// appId / apiKey / index may be undefined (e.g. straight off process.env) —
// sync pauses with a warning until they're set
algolia: { appId, apiKey, index, clientOptions? },
collections: {
pages: true, // defaults
drafts: false, // same as omitting — handy for conditional config
news: {
excludeFields?: string[], // replace the effective exclude list
contentLimit?: number, // per-collection content cap
getPath?: ({ collection, doc, req }) => string | null | undefined, // override the global getPath
record?: ({ collection, doc, req, defaultRecord }) => record | null | undefined,
// ^ doc is typed from your generated Payload types in both callbacks
},
},
getPath?: ({ collection, doc, req }) => string | null | undefined,
excludeFields?: string[], // replace defaultExcludeFields
contentLimit?: number, // default 4000
awaitSync?: boolean, // default true — await Algolia writes in hooks (see below)
waitUntil?: (promise) => void, // scheduler for background writes when awaitSync: false (auto-detected on Vercel)
enabled?: boolean, // false returns the config untouched
indexSettings?: IndexSettings | false, // merged over defaultIndexSettings; false = never write
richTextConverters?: {...}, // forwarded to convertLexicalToPlaintext
richTextToText?: (value) => string, // replace rich text extraction
reindex?: boolean | { // true/omitted = defaults, false disables all of it
path?: string, // default '/algolia-search/reindex'
access?: ({ req }) => boolean | Promise<boolean>, // guards the endpoint + header icon; default: any authenticated user
batchSize?: number, // default 100
depth?: number, // default 0
button?: boolean, // false hides the admin header icon
},
})
awaitSync)By default hooks await the Algolia write, so every save waits one Algolia round trip. That is
durable everywhere, which is why it's the default. Set awaitSync: false to let saves return
immediately and sync in the background — but only where background work is guaranteed to finish:
Vercel — works out of the box; no waitUntil option needed:
algoliaSearchPlugin({
// ...
awaitSync: false, // that's it — waitUntil is picked up automatically
})
The plugin reads the runtime's request context (Symbol.for('@vercel/request-context') — the
same global @vercel/functions reads) and hands the write to its waitUntil, which keeps the
invocation alive until the write lands without delaying the response. Passing the official
@vercel/functions export via the waitUntil option also works, but is redundant.
Long-lived servers (Docker, VPS, next start self-hosted) — safe; the process outlives the
request anyway.
Other platforms with a waitUntil primitive — pass it via the waitUntil option, e.g.
Cloudflare Workers via OpenNext: waitUntil: (p) => getCloudflareContext().ctx.waitUntil(p).
Runtimes that freeze after the response (bare AWS Lambda and anything built on it) and scripts that exit immediately (seeds using the Local API) — keep the default. There is no after-response hook to attach to, so background writes can be silently dropped.
The promise handed to waitUntil never rejects — sync failures are logged through
payload.logger either way.
| Event | Index action |
|---|---|
| First draft (never published) | ignored |
| Autosave/draft save over a published doc | ignored — published record stays live |
| Publish / restore published version | record saved |
| Unpublish (no published version remains) | record removed |
Trash (deletedAt) | record removed |
| Permanent delete | record removed |
Collection record transform returns null | record removed |
Sync failures never block a save — errors are logged through payload.logger and the document operation succeeds.
Draft/unpublish semantics adapted from payload-plugin-algolia by Will Kent-Daggett (MIT).
search
Generate fast-to-query search records from your Payload documents
100128.3k/wk46.1kv3 v4
payload plugin algolia
Sync Payload collections to an Algolia search index
54124/wk17v3
payload meilisearch
Sync Payload collections to Meilisearch indexes on create, update and delete
3925/wk39v1
payload algolia search
Sync Payload collections to Algolia with search and re-index endpoints plus optional result enrichment
3522/wk1v3
payload typesense
Typesense search for Payload with automatic sync, search endpoints, optional vector search and React search components
851.4k/wk33v3 v4
payload plugin cache refresh
Admin dashboard button that refreshes Next.js cache tags for permitted users, with confirmation and optional page…
78385/wk0v3