algoliasearch package is version 5.
This page helps you upgrade from version 4
and explains the breaking changes you need to address.
Algolia generates the version 5 clients from OpenAPI specifications,
which provides consistent behavior across all languages and up-to-date API coverage.
The main architectural change is the removal of the initIndex pattern:
all methods are now on the client instance directly, with indexName as a parameter.
For the full list of changes, see the JavaScript changelog.
Update your dependencies
Update thealgoliasearch package to version 5:
Command line
Update imports
The import style changed from a default export to a named export.JavaScript
JavaScript
JavaScript
Update client initialization
Client creation is unchanged. The constructor still accepts your application ID and API key:JavaScript
initIndex no longer exists.
Remove initIndex
This is the most significant change when upgrading.
Version 4 relied on an index object with methods called on it.
In version 5, all methods belong to the client instance,
with indexName as a parameter.
JavaScript
Update search calls
Search a single index
Theindex.search() method is now client.searchSingleIndex().
Pass the index name and search parameters as an object:
JavaScript
Search multiple indices
Theclient.multipleQueries() method is now client.search().
Each request in the array requires an indexName:
JavaScript
Search for facet values
Theindex.searchForFacetValues() method becomes client.searchForFacetValues()
with an indexName parameter:
JavaScript
Update indexing operations
In version 5, indexing methods are on the client instead of the index object, withindexName as a parameter.
Add or replace records
JavaScript
Partially update records
JavaScript
Delete records
JavaScript
Update settings, synonyms, and rules
Get and set settings
JavaScript
Save synonyms and rules
JavaScript
In version 4,
index.replaceAllRules() and index.replaceAllSynonyms() replaced all rules or synonyms.
In version 5, use client.saveRules() or client.saveSynonyms() with the clearExistingRules or clearExistingSynonyms parameter set to true.Update index management
ThecopyIndex, moveIndex, copyRules, copySynonyms, and copySettings
methods are all replaced by a single operationIndex method.
Copy an index
JavaScript
Move (rename) an index
JavaScript
Copy only rules or settings
In version 5, use thescope parameter to limit the operation to specific data:
JavaScript
Check if an index exists
In version 4, you could check if an index existed using theexists method on the index object.
In version 5, use the indexExists helper method on the client:
JavaScript
Update task handling
Version 4 supported chaining.wait() on operations.
Version 5 replaces this pattern with dedicated wait helpers.
JavaScript
waitForTask: wait until indexing operations are done.waitForAppTask: wait for application-level tasks.waitForApiKey: wait for API key operations.
Helper method changes
The following sections document breaking changes in helper method signatures and behavior between version 4 and version 5.replaceAllObjects
The safe option has been removed. In version 4, safe: true caused the helper to wait after each step. In version 5, the helper always waits—equivalent to the previous safe: true behavior.
The scopes parameter is now required and must be passed explicitly.
JavaScript
saveObjects
The autoGenerateObjectIDIfNotExist option has been removed. In version 5, you must provide an objectID on every object, or use the chunkedBatch helper with the action parameter set to addObject if you want the API to generate object IDs.
Two new optional parameters are available:
waitForTasks(waits for all indexing tasks to complete before returning, defaultfalse)batchSize(controls how many objects are sent per API call, default1,000)
JavaScript
deleteObjects
Two new optional parameters are available:
waitForTasks(waits for all indexing tasks to complete before returning, defaultfalse)batchSize(controls how many objects are sent per API call, default1,000)
JavaScript
partialUpdateObjects
Two new optional parameters are available: waitForTasks and batchSize.
JavaScript
browseObjects, browseRules, browseSynonyms
These helpers now accept an aggregator callback instead of returning an iterator. The helper calls aggregator with each page of results as it paginates. An optional validate callback can be used to stop early.
JavaScript
generateSecuredApiKey
The method signature has changed from positional parameters to a single object parameter.
JavaScript
getSecuredApiKeyRemainingValidity
The method signature changed from a positional string argument to an object parameter.
JavaScript
waitForTask
The helper was renamed from waitTask to waitForTask and now takes indexName as an explicit parameter.
JavaScript
waitForAppTask
The helper was renamed from waitAppTask to waitForAppTask for consistency with waitForTask and waitForApiKey.
JavaScript
waitForApiKey
In version 4, waiting for API key operations was done by calling .wait() on the WaitablePromise returned by addApiKey, updateApiKey, deleteApiKey, or restoreApiKey. Version 5 provides a standalone waitForApiKey helper.
JavaScript
indexExists
The helper was renamed from exists() on the index object to indexExists() on the client.
JavaScript
chunkedBatch
chunkedBatch is now a public helper. In version 4, chunking was an internal implementation detail of saveObjects. The action parameter defaults to "addObject".
JavaScript
accountCopyIndex
In version 4, accountCopyIndex was part of the separate @algolia/client-account package and accepted two initialized SearchIndex objects. In version 5, it’s a built-in helper on the algoliasearch client and accepts a flat options object with string identifiers.
JavaScript
saveObjectsWithTransformation
In version 4, this method was available on index objects via the ingestion mixin. In version 5, it’s a top-level helper on the algoliasearch client. It routes objects through the Algolia Push connector and requires transformation.region to be set at client initialization.
JavaScript
replaceAllObjectsWithTransformation
New in version 5. Atomically replaces all objects via the Push connector (copy settings/rules/synonyms to a temp index → push objects → move back). Requires transformation.region at client initialization.
JavaScript
partialUpdateObjectsWithTransformation
New in version 5. Routes partial updates through the Push connector. The createIfNotExists parameter defaults to false.
JavaScript
Method changes reference
The following tables list all method names that changed between version 4 and version 5.Search API client
| Version 4 (legacy) | Version 5 (current) | |
|---|---|---|
client.addApiKey | → | client.addApiKey |
client.addApiKey.wait | → | client.waitForApiKey |
client.clearDictionaryEntries | → | client.batchDictionaryEntries |
client.copyIndex | → | client.operationIndex |
client.copyRules | → | client.operationIndex |
client.copySynonyms | → | client.operationIndex |
client.deleteApiKey | → | client.deleteApiKey |
client.deleteDictionaryEntries | → | client.batchDictionaryEntries |
client.generateSecuredApiKey | → | client.generateSecuredApiKey |
client.getApiKey | → | client.getApiKey |
client.getSecuredApiKeyRemainingValidity | → | client.getSecuredApiKeyRemainingValidity |
client.listApiKeys | → | client.listApiKeys |
client.listIndices | → | client.listIndices |
client.moveIndex | → | client.operationIndex |
client.multipleBatch | → | client.multipleBatch |
client.multipleQueries | → | client.search |
client.replaceDictionaryEntries | → | client.batchDictionaryEntries |
client.restoreApiKey | → | client.restoreApiKey |
client.saveDictionaryEntries | → | client.batchDictionaryEntries |
client.updateApiKey | → | client.updateApiKey |
index.batch | → | client.batch |
index.browseObjects | → | client.browseObjects |
index.browseRules | → | client.browseRules |
index.browseSynonyms | → | client.browseSynonyms |
index.clearObjects | → | client.clearObjects |
index.clearRules | → | client.clearRules |
index.clearSynonyms | → | client.clearSynonyms |
index.copySettings | → | client.operationIndex |
index.delete | → | client.deleteIndex |
index.deleteBy | → | client.deleteBy |
index.deleteObject | → | client.deleteObject |
index.deleteObjects | → | client.deleteObjects |
index.deleteRule | → | client.deleteRule |
index.deleteSynonym | → | client.deleteSynonym |
index.exists | → | client.indexExists |
index.findObject | → | client.searchSingleIndex |
index.getObject | → | client.getObject |
index.getObjects | → | client.getObjects |
index.getRule | → | client.getRule |
index.getSettings | → | client.getSettings |
index.getSynonym | → | client.getSynonym |
index.getTask | → | client.getTask |
index.partialUpdateObject | → | client.partialUpdateObject |
index.partialUpdateObjects | → | client.partialUpdateObjects |
index.replaceAllObjects | → | client.replaceAllObjects |
index.replaceAllRules | → | client.saveRules |
index.replaceAllSynonyms | → | client.saveSynonyms |
index.saveObject | → | client.saveObject |
index.saveObjects | → | client.saveObjects |
index.saveRule | → | client.saveRule |
index.saveRules | → | client.saveRules |
index.saveSynonym | → | client.saveSynonym |
index.saveSynonyms | → | client.saveSynonyms |
index.search | → | client.searchSingleIndex |
index.searchForFacetValues | → | client.searchForFacetValues |
index.searchRules | → | client.searchRules |
index.searchSynonyms | → | client.searchSynonyms |
index.setSettings | → | client.setSettings |
index.{operation}.wait | → | client.waitForTask |
Recommend API client
| Version 4 (legacy) | Version 5 (current) | |
|---|---|---|
client.getFrequentlyBoughtTogether | → | client.getRecommendations |
client.getLookingSimilar | → | client.getRecommendations |
client.getRecommendations | → | client.getRecommendations |
client.getRelatedProducts | → | client.getRecommendations |
client.getTrendingFacets | → | client.getRecommendations |
client.getTrendingItems | → | client.getRecommendations |