This page documents an earlier version of the API client. For the latest version, see Upgrade.
Upgrade to version 3
The client and index class have been renamedSearchClient and SearchIndex. The method names remain the same.
To have all the asynchronous and synchronous methods in the same place, the asynchronous client is now part of the SearchClient.
The Analytics and Insights clients use the same API design.
This version is compatible with Java 8 and later.
This version removes all deprecated methods and features from version 2.
Upgrade the library
The library now comes in two parts.algoliasearch-corewhich holds all the methods, the plain old Java object (POJO), the transport layer and the retry strategy. This JAR is agnostic of any HTTP client implementation.algoliasearch-apachewhich is the default HTTP client implementation for the core library.
Upgrade with maven
Add the following code in yourpom.xml:
pom.xml
Upgrade with Gradle
Add the following code in yourbuild.gradle:
build.gradle
Client instantiation
Replace the instantiation of the client as shown below.Java
Instantiate with configuration
You can instantiate all clients with a configuration builder. This is useful to affect the way a client behaves. You can configure :- DefaultHeaders: to set HTTP headers for every request
- BatchSize: to customize the chunk size of batches for save methods
- Hosts: to set custom hosts to target
- Timeouts : to set timeout such as the read timeout, the write timeout, and the connect timeout
- ExecutorService: to set your own
ExecutorService
Java
Analytics instantiation
Similarly, you need to update the way you initialize the Analytics client.Java
Insights instantiation
You need to update the way you initialize the Insights client:Java
Breaking changes
To ease the update, most of the plain old java objects (POJO) didn’t change. You can find some breaking changes in the following table. All methods marked as@Depracted are removed.
Clients
| Methods/Features in version 2 | Breaking Change | Methods/Features in version 3 |
|---|---|---|
APIClient | Removed. Use SearchClient AnalyticsClient InsightsClient instead. | DefaultSearchClient.create(..) DefaultAnalyticsClient.create(..) DefaultInsightsClient.create(..) |
AsyncAPIClient | Removed. Use SearchClient AnalyticsClient InsightsClient instead. | DefaultSearchClient.create(..) DefaultAnalyticsClient.create(..) DefaultInsightsClient.create(..) |
SearchClient
| Methods/Features in version 2 | Breaking Change | Methods/Features in version 3 |
|---|---|---|
listKeys() | Removed. Use listApiKeys() instead. | listApiKeys() |
Index/SearchIndex
| Methods/Features in version 2 | Breaking Change | Methods/Features in version 3 |
|---|---|---|
deleteByQuery(query) | Removed. Use deleteBy() instead. | deleteBy(query) |
searchInFacetValues(facetName,facetQuery,query) | Removed. Use searchForFacetValues() instead. | searchForFacetValues(String, String, Query) |
index.browse(Query) | Breaking | index.browseObjects(BrowseIndexQuery) |
BrowseResult<T> | Breaking | BrowseIndexResponse<T> |
IndexSetting.getAttributesToIndex() | Removed. Use searchableAttributes instead. | IndexSetting.getSearchableAttributes() |
IndexSetting.setAttributesToIndex() | Removed. Use searchableAttributes instead. | IndexSetting.setSearchableAttributes() |
Query.setFacetFilters(List<String>) | Breaking | Query.setFacetFilters(List) |
Query.setNumericFilters(List<String>) | Breaking | Query.setNumericFilters(List) |
Query.setTagFilters(List<String>) | Breaking | Query.setTagFilters(List) |
Query.setOptionalFilters(List<String>) | Breaking | Query.setOptionalFilters(List) |
AbstractSynonym | Removed. Use Synonym instead. | Synonym |
ConsequenceQueryObject | Removed. Use ConsequenceQuery instead. | ConsequenceQuery |
ConsequenceQueryObject.setRemove(List<String>) | Removed. Use ConsequenceQuery.setEdits() instead. | ConsequenceQuery.setEdits(List<Edits>>) |
Index<T>.addObject(T object) | Removed. Use SearchIndex<T>.saveObject(T data) instead. | SearchIndex<T>.saveObject(T data) |
AnalyticsClient
| Methods/Features in version 2 | Breaking Change | Methods/Features in version 3 |
|---|---|---|
TaskABTest addABTest(ABTest abtest) | Breaking | AddABTestResponse addABTest(ABTest abTest) |
TaskABTest stopABTest(long id) | Breaking | StopAbTestResponse stopABTest(long id) |
TaskABTest deleteABTest(long id) | Breaking | DeleteAbTestResponse deleteABTest(long id) |
ABTest getABTest(long id) | Breaking | ABTestResponse getABTest(long id) |