algoliasearch-client-php package is version 4.
This page helps you upgrade from version 3
and explains the breaking changes you need to address.
Algolia generates the version 4 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 PHP changelog.
Update your dependencies
Update thealgoliasearch-client-php package to version 4:
Command line
Update imports
The namespace for API clients changed in version 4. TheSearchClient class moved from Algolia\AlgoliaSearch to Algolia\AlgoliaSearch\Api.
PHP
PHP
Update client initialization
Client creation uses the sameSearchClient::create() factory method.
The constructor still accepts your application ID and API key:
PHP
Remove initIndex
This is the most significant change when upgrading.
Version 3 relied on an index object with methods called on it.
In version 4, all methods belong to the $client instance,
with indexName as a parameter.
PHP
Use model classes or associative arrays
Version 4 methods accept both model classes and associative arrays as parameters.PHP
Update search calls
Search a single index
The$index->search() method is now $client->searchSingleIndex().
Pass the index name and search parameters as positional arguments:
PHP
Search multiple indices
The$client->multipleQueries() method is now $client->search().
Each request in the array requires an indexName:
PHP
Search for facet values
The$index->searchForFacetValues() method becomes $client->searchForFacetValues()
with an indexName parameter:
PHP
Update indexing operations
In version 4, indexing methods are on the client instead of the index object, withindexName as a parameter.
Add or replace records
PHP
Partially update records
PHP
Delete records
PHP
Update settings, synonyms, and rules
Get and set settings
PHP
Save synonyms and rules
PHP
In version 3,
$index->replaceAllRules() and $index->replaceAllSynonyms() replaced all rules or synonyms.
In version 4, use $client->saveRules() or $client->saveSynonyms() with the clearExistingRules or replaceExistingSynonyms 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
PHP
Move (rename) an index
PHP
Copy only rules or settings
In version 4, use thescope parameter to limit the operation to specific data:
PHP
Check if an index exists
In version 3, you could check if an index existed using theexists method on the index object.
In version 4, use the indexExists helper method on the client:
PHP
Update task handling
Version 3 supported chaining->wait() on operations.
Version 4 replaces this pattern with dedicated wait helpers.
PHP
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 3 and version 4.replaceAllObjects
The 'safe' request option has been removed. In version 3, passing 'safe' => true caused the helper to wait after each step. In version 4, the helper always waits—equivalent to the previous 'safe' => true behavior.
The scopes parameter is now required and must be passed explicitly.
PHP
saveObjects
The autoGenerateObjectIDIfNotExist request option has been removed. In version 4, every object must include an objectID. To have the API generate object IDs, use chunkedBatch with action: 'addObject'.
PHP
partialUpdateObjects
The createIfNotExists option has moved from the $requestOptions array to an explicit required parameter.
PHP
deleteObjects
The helper moved to the client and two new optional parameters are available: $waitForTasks (default false) and $batchSize (default 1,000). The parameter was also renamed from $objectIds to $objectIDs.
PHP
browseObjects, browseRules, browseSynonyms
These helpers still return iterator objects in version 4. The only change is that $indexName is now an explicit first parameter instead of being implicit from the index object.
PHP
generateSecuredApiKey and getSecuredApiKeyRemainingValidity
For generateSecuredApiKey, the restrictions parameter now uses a typed SecuredApiKeyRestrictions model instead of a plain array.
For getSecuredApiKeyRemainingValidity, the parameter was renamed from $securedAPIKey to $securedApiKey.
PHP
waitForTask
The method was renamed from waitTask to waitForTask. It also gained optional $maxRetries and $timeout parameters for controlling retry behavior.
PHP
waitForAppTask
This is a new helper in version 4.
PHP
waitForApiKey
This is a new standalone helper in version 4. In version 3, you had to poll getApiKey manually after key mutations.
PHP
indexExists
The helper was renamed from exists() on the index object to indexExists() on the client.
PHP
chunkedBatch
chunkedBatch is now a public helper. In version 3, chunking was an internal implementation detail of saveObjects. The default $action is 'addObject' and the default $waitForTasks is false.
PHP
copyIndexBetweenApplications
In version 3, the separate Algolia\AccountClient class provided a static copyIndex method for copying an index between two different Algolia applications. It accepted two SearchIndex objects and raised an exception if the destination already existed or if both indices were in the same application.
In version 4, AccountClient is removed. You can compose existing helpers across two clients to achieve the same result.
PHP
saveObjectsWithTransformation
New in version 4. Routes objects through the Algolia Push connector. Requires setTransformationRegion to be called at client initialization.
PHP
replaceAllObjectsWithTransformation
New in version 4. Atomically replaces all objects via the Push connector (copy settings/rules/synonyms to a temp index → push objects → move back). Requires setTransformationRegion at client initialization.
PHP
partialUpdateObjectsWithTransformation
New in version 4. Routes partial updates through the Push connector. The $createIfNotExists parameter is required with no default value.
PHP
Method changes reference
The following tables list all method names that changed between version 3 and version 4.Search API client
| Version 3 (legacy) | Version 4 (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 3 (legacy) | Version 4 (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 |