Upgrade the Java API clients to v4

The latest major version of the algoliasearch package is v4. This page lists the breaking changes since the last release, v3.

Removal of initIndex

All methods are methods of a client instance. The initIndex method of the SearchClient class has been removed. Instead, all methods require a indexName parameter.

1
2
3
4
5
6
7
8
9
10
11
12
// v3
var client = DefaultSearchClient.create("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");
var index = client.initIndex("ALGOLIA_INDEX_NAME", Record.class);
index.search(new Query("QUERY"));

// v4
var client = new SearchClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");
client.searchSingleIndex(
    "ALGOLIA_INDEX_NAME",
    new SearchParamsObject().setQuery("QUERY"),
    Hit.class,
)

Wait for tasks

The wait method has been removed. Instead, use one of the following helpers:

Copy or moving indices, settings, synonyms, or rules

Use the operationIndex method, which replaces the following methods:

  • copyIndex
  • moveIndex
  • copyRules
  • copySynonyms
  • copySettings
Did you find this page helpful?
Java API clients v4