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:
Command line
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
Check if an index exists
In version 3, you could check if an index existed using theExists method on the index object.
In version 4, use the IndexExists helper method on the client:
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.
Helper method changes
The following sections document breaking changes in helper method signatures and behavior between version 3 and version 4.ReplaceAllObjects
The opt.Safe() functional option has been removed. In version 3, passing opt.Safe(true) caused the helper to wait after each step. In version 4, the helper always waits—equivalent to the previous opt.Safe(true) behavior.
Go
SaveObjects
The opt.AutoGenerateObjectIDIfNotExist() functional option has been removed. In version 4, every object must include an ObjectID. To have the API generate object IDs, use ChunkedBatch with search.ACTION_ADD_OBJECT.
Go
PartialUpdateObjects
The opt.CreateIfNotExists() functional option has been replaced with an explicit field on the params struct. The default also changed: in version 3 it defaulted to false (used partialUpdateObjectNoCreate); in version 4 it defaults to true.
Go
BrowseObjects, BrowseRules, BrowseSynonyms
The ObjectIterator, RuleIterator, and SynonymIterator types have been removed. These helpers now use an Aggregator callback that is called with each page of results.
Go
DeleteObjects
Two new optional parameters are available:
WithWaitForTasks(bool)(defaultfalse)WithBatchSize(int)(default1,000)
Go
WaitForTask
The helper was renamed from WaitTask to WaitForTask, moved to the client, and now returns *GetTaskResponse instead of error. The timeToWait config option is replaced by explicit WithMaxRetries and WithTimeout options—the default timeout uses exponential backoff capped at 5 seconds.
Go
WaitForAppTask
This is a new helper in version 4.
Go
WaitForApiKey
This is a new standalone helper in version 4. In version 3, waiting for API key operations required polling GetAPIKey manually.
Go
IndexExists
The helper was renamed from Exists() on the index object to IndexExists() on the client.
Go
GenerateSecuredApiKey
The function moved from a package-level function to a method on the client and was renamed from GenerateSecuredAPIKey to GenerateSecuredApiKey. The restrictions are now a single typed struct instead of variadic functional options.
Go
GetSecuredApiKeyRemainingValidity
The method was renamed from GetSecuredAPIKeyRemainingValidity to GetSecuredApiKeyRemainingValidity. The variadic options parameter has been removed.
Go
ChunkedBatch
ChunkedBatch is now a public helper. In version 3, chunking was an internal detail of SaveObjects. The action parameter is required.
Go
CopyIndexBetweenApplications
In version 3, the Account type provided a CopyIndex method for copying an index between two different Algolia applications. It accepted two *Index values, each carrying its own app credentials.
In version 4, the Account type is removed. You can compose existing helpers across two clients to achieve the same result.
Go
SaveObjectsWithTransformation
New in version 4. Routes objects through the Algolia Push connector. Requires the IngestionTransporter to be configured at client initialization via a region.
Go
ReplaceAllObjectsWithTransformation
New in version 4. Atomically replaces all objects via the Push connector (copy settings/rules/synonyms to a temp index → push objects → move back). Requires the IngestionTransporter to be configured at client initialization.
Go
PartialUpdateObjectsWithTransformation
New in version 4. Routes partial updates through the Push connector. The createIfNotExists option defaults to false.
Go
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.Exists | → | client.IndexExists |
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 |