Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
A Gatsby plugin that indexes GraphQL query results into Algolia during the build step.
gatsby-plugin-algolia is a Gatsby plugin that indexes GraphQL query results into Algolia during the build step, enabling site search without a dedicated search backend. It is currently in beta and not officially supported, but it works with any Gatsby site and requires an Algolia account.
gatsby-plugin-algolia is a community plugin that pushes data from your Gatsby site to an Algolia index when you run gatsby build. You define one or more GraphQL queries in your Gatsby config, and the plugin transforms the query results into an array of objects that are then uploaded to Algolia. It runs only during the build process, not in development, to help you avoid exceeding your Algolia quota while working locally.
gatsby-config.js; each query can target its own index, with optional per-query settings and variables.internal.contentDigest field (which must be included in your query).mergeSettings lets you preserve manual changes made on the Algolia website, though deleted settings persist unless removed from both config and Algolia.chunkSize defaults to 1000 objects per batch, helping avoid request size limits.concurrentQueries: false to run queries sequentially on platforms like Netlify where concurrent access can cause hanging builds.dryRun calculates which objects would be indexed without pushing, and continueOnFailure prevents a failed Algolia push from failing the entire Gatsby build.dotenv, with the .env.production file commonly used for build-time secrets.dryRun to preview which objects would be indexed before committing to the feature.First, install the plugin and add your Algolia credentials to an environment file that is not committed to version control. Then define GraphQL queries in your Gatsby config, each with a transformer function and a target index name. When you run gatsby build, the plugin executes each query, transforms the result nodes into objects, and uploads them to Algolia in chunks, respecting your configured concurrency and threshold settings.
The plugin is lightweight and integrates directly with Gatsby's build lifecycle, but it is in beta and carries some limitations.
gatsby build, so development changes won't be reflected until a build is triggered.mergeSettings is false, supplying settings in the config overwrites all existing settings on the Algolia index.If you are running in development mode, remember that the plugin only pushes to Algolia during gatsby build. Also check that your query includes the internal.contentDigest field; some plugins don't regenerate this field when content changes, so you may need a custom transformer to compute a fresh digest.
This plugin itself is open source and free, but you will need an Algolia account and are subject to Algolia's own pricing and quotas. The plugin avoids pushing during development to help you stay within those quotas.
The plugin defaults to overwriting your entire Algolia index settings on each build, using the settings from your Gatsby config. Setting mergeSettings to true merges the config settings with the existing index settings, giving precedence to the config values; however, settings deleted from the config will persist unless you also delete them on Algolia's website.
The transformer field accepts either a synchronous or an async function. You can for example compute an MD5 hash of each object's JSON string using Node's crypto module and replace the provided contentDigest with that hash, ensuring changed content produces a new digest.
It is built for Gatsby and should work with recent versions that support gatsby-config.js and GraphQL queries. Since it is in beta and not officially supported, check the GitHub issues for any reported compatibility problems with your specific Gatsby setup.
