algoliasearch 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 Java changelog.
Update your dependencies
Version 4 consolidates the separatealgoliasearch-core and HTTP client packages
into a single algoliasearch artifact.
You no longer need algoliasearch-apache or algoliasearch-java-net.
Maven
Replace your Algolia dependencies inpom.xml:
pom.xml
Gradle
Update yourbuild.gradle file:
build.gradle
Update imports
The package structure changed. Client classes moved fromcom.algolia.search to com.algolia.api,
and model classes moved to com.algolia.model.search.
Java
Java
Update client initialization
In version 3, theDefaultSearchClient.create() factory method created the client.
Version 4 removes this factory. Use the SearchClient constructor instead.
Java
Closeable.
Use try-with-resources to ensure the client is properly closed:
Java
Understand the new API surface
Version 4 introduces two major changes to the API surface:- No more
initIndex. In version 3, the client created a typedSearchIndex<T>object with methods called on it. In version 4, theSearchIndexclass is gone. All methods belong to theclientinstance, withindexNameas a parameter. - Generic type parameter moves to each method call.
In version 3, you set the result type once on
initIndex("INDEX", Record.class). In version 4, you pass the target class (for example,Hit.class) as the last argument to each method that returns typed results, such assearchSingleIndexorgetObject.
Java
Update search calls
Search a single index
Theindex.search() method is now client.searchSingleIndex().
Pass the index name, a SearchParamsObject, and the target class:
Java
Search multiple indices
Theclient.multipleQueries() method is now client.search().
Each request in the list requires an indexName:
Java
Search for facet values
Theindex.searchForFacetValues() method becomes client.searchForFacetValues()
with an indexName parameter:
Java
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
Java
Partially update records
Java
Delete records
Java
Update settings, synonyms, and rules
Get and set settings
Java
Save synonyms and rules
Java
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 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
Java
Move (rename) an index
Java
Copy only rules or settings
In version 4, use thescope parameter to limit the operation to specific data:
Java
Update task handling
Version 3 supported chaining.waitTask() on operations.
Version 4 replaces this pattern with dedicated wait helpers.
Java
waitForTask: wait until indexing operations are done.waitForAppTask: wait for application-level tasks.waitForApiKey: wait for API key operations.
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.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.getRecommendations | → | client.getRecommendations |
client.getRelatedProducts | → | client.getRecommendations |