The perfect starting point to integrate Algolia within your Go project
Documentation • Community Forum • Stack Overflow • Report a bug • FAQ • Support
- Support Go 1.19 and above
- Typed requests and responses
- First-class support for user-defined structures
- Injectable HTTP client
First, install the Algolia API Go Client via the go get command:
go get github.com/algolia/algoliasearch-client-go/v4
You can now import the Algolia API client in your project and play with it.
import "github.com/algolia/algoliasearch-client-go/v4/algolia/search"
client, err := search.NewClient("YOUR_APP_ID", "YOUR_API_KEY")
// Add a new record to your Algolia index
response, err := client.SaveObject(client.NewApiSaveObjectRequest(
"<YOUR_INDEX_NAME>", map[string]any{"objectID": "id", "test": "val"},
))
if err != nil {
// handle the eventual error
panic(err)
}
// use the model directly
print(response)
// Poll the task status to know when it has been indexed
taskResponse, err := searchClient.WaitForTask("<YOUR_INDEX_NAME>", response.TaskID, nil, nil, nil)
if err != nil {
panic(err)
}
// Fetch search results, with typo tolerance
response, err := client.Search(client.NewApiSearchRequest(
search.NewEmptySearchMethodParams().SetRequests(
[]search.SearchQuery{*search.SearchForHitsAsSearchQuery(
search.NewEmptySearchForHits().SetIndexName("<YOUR_INDEX_NAME>").SetQuery("<YOUR_QUERY>").SetHitsPerPage(50))}),
))
if err != nil {
// handle the eventual error
panic(err)
}
// use the model directly
print(response)
For full documentation, visit the Algolia Go API Client.
Encountering an issue? Before reaching out to support, we recommend heading to our FAQ where you will find answers for the most common issues and gotchas with the client. You can also open a GitHub issue
This repository hosts the code of the generated Algolia API client for Go, if you'd like to contribute, head over to the main repository. You can also find contributing guides on our documentation website.
The Algolia Go API Client is an open-sourced software licensed under the MIT license.