diff --git a/README.md b/README.md index 4234c7a..8f1491e 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,9 @@ module.exports = { matchFields: ['slug', 'modified'], // Array default: ['modified'] concurrentQueries: false, // default: true skipIndexing: true, // default: false, useful for e.g. preview deploys or local development - continueOnFailure: false // default: false, don't fail the build if algolia indexing fails + continueOnFailure: false, // default: false, don't fail the build if algolia indexing fails + useEnvironment: 'blog', // default: false, used in conjunction with enablePartialUpdates let you persist entries from different environment + environmentKey: 'product', // default: 'environment', key used when useEnvironment is set. }, }, ], @@ -128,6 +130,9 @@ If you pass `replicaUpdateMode: 'replace'` in the index settings, you can choose If you pass `replicaUpdateMode: 'merge'` in the index settings, the replica settings will combine the replicas set on your dashboard with the additional ones you set via index settings here. +### Persisting entries +If you want to persist entries that are added to the index (for example added by the different gatsby instance if your index is combining several websites) you can set `useEnvironment` to unique string that represents given instance. All entries with different `environment` value will be ignored. You can change the key accordingly using `environmentKey`. + ## Concurrent Queries Sometimes, on limited platforms like Netlify, concurrent queries to the same index can lead to unexpected results or hanging builds. Setting `concurrentQueries` to `false` makes it such that queries are run sequentially rather than concurrently, which may solve some concurrent access issues. Be aware that this option may make indexing take longer than it would otherwise. diff --git a/gatsby-node.js b/gatsby-node.js index e806b92..99b97c3 100755 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -115,6 +115,8 @@ async function runIndexQueries( chunkSize = 1000, enablePartialUpdates = false, matchFields: mainMatchFields = ['modified'], + useEnvironment = false, + environmentKey = 'environment' } = config; activity.setStatus( @@ -173,6 +175,9 @@ async function runIndexQueries( // iterate over existing objects and compare to fresh data for (const [id, existingObj] of Object.entries(indexedObjects)) { + if (useEnvironment && existingObj[environmentKey] !== useEnvironment) { + continue; + } if (queryResultsMap.hasOwnProperty(id)) { // key matches fresh objects, so compare match fields const newObj = queryResultsMap[id];