algoliasearch-client-go 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 Go changelog.
Update your dependencies
Update thealgoliasearch-client-go package to version 4:
Update imports
The import path changed fromv3 to v4:
Go
Update client initialization
In version 3,NewClient returned a client directly.
In version 4, it returns a (client, error) pair, so you need to handle the error:
Go
Understand the new API surface
Version 4 introduces two major changes to the API surface:- No more
InitIndex. Version 3 relied on an index object with methods called on it. In version 4, all methods belong to theclientinstance, withindexNameas a parameter. - Builder pattern for requests.
Version 4 introduces typed request builders (
NewApi*Requestconstructors) withWith*methods for optional parameters.
Go
Update search calls
Search a single index
Theindex.Search() method is now client.SearchSingleIndex().
Build the request with NewApiSearchSingleIndexRequest and attach search parameters with WithSearchParams:
Go
Search multiple indices
Theclient.MultipleQueries() method is now client.Search().
Each query in the request requires an IndexName:
Go
Search for facet values
Theindex.SearchForFacetValues() method becomes client.SearchForFacetValues()
with an indexName parameter:
Go
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
Go
Partially update records
Go
Delete records
Go
Update settings, synonyms, and rules
Get and set settings
Go
Save synonyms and rules
Go
In version 3,
index.ReplaceAllRules() and index.ReplaceAllSynonyms() replaced all rules or synonyms.
In version 4, use client.SaveRules() or client.SaveSynonyms() with the WithClearExistingRules(true) or WithReplaceExistingSynonyms(true) option on the request builder.Update index management
TheCopyIndex, MoveIndex, CopyRules, CopySynonyms, and CopySettings
methods are all replaced by a single OperationIndex method.
Copy an index
Go
Move (rename) an index
Go
Copy only rules or settings
In version 4, use theSetScope parameter to limit the operation to specific data:
Go
Update task handling
Version 3 supported chaining.Wait() on operations.
Version 4 replaces this pattern with dedicated wait helpers.
Go
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.GetStatus | → | 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 |