Oct 21, 2024
Upgrade the JavaScript API clients to v5
The latest major version of the algoliasearch
package is v5.
This page lists the breaking changes since the last release, v4.
Method changes overview
The following table has links for all methods and their replacements
Search API client
Recommend API client
Client imports
The imports for the API clients changed.
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Search API, A/B testing API, Analytics API, Personalization API
import { algoliasearch } from "algoliasearch";
// Search methods only
import { liteClient as algoliasearch } from "algoliasearch/lite";
// Search API
import { searchClient } from "@algolia/client-search";
// Recommend API
import { recommendClient } from "@algolia/recommend";
// A/B testing API
import { abtestingClient } from "@algolia/client-abtesting";
// Analytics API (new in v5)
import { analyticsClient } from "@algolia/client-analytics";
// Personalization API
import { personalizationClient } from "@algolia/client-personalization";
// Query Suggestions API (new in v5)
import { querySuggestionsClient } from "@algolia/client-query-suggestions";
Removal of initIndex
All methods are methods of a client
instance.
The initIndex
method of the searchClient
has been removed.
Instead, all methods require an indexName
parameter.
Copy
1
2
3
4
5
6
7
8
9
10
11
// v4
const client = algoliasearch("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");
const index = client.initIndex("ALGOLIA_INDEX_NAME");
const results = index.search("QUERY");
// v5
const client = algoliasearch("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");
const results = await client.searchSingleIndex({
indexName: "ALGOLIA_INDEX_NAME",
searchParams: {query: "QUERY"},
});
Wait for tasks
The wait
method has been removed.
Instead, use one of the following helpers:
wait_for_task
to wait until indexing operations are donewait_for_app_task
to wait for application-level taskswait_for_api_key
to wait for API key operations
Copy or move 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?