Add or replace a record

If a record with the specified object ID exists, the existing record is replaced. Otherwise, a new record is added to the index.

If you want to use auto-generated object IDs, use the saveObject operation. To update some attributes of an existing record, use the partial operation instead. To add, update, or replace multiple records, use the batch operation.

Usage

Required ACL: addObject
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import "github.com/algolia/algoliasearch-client-go/v4/algolia/search"

client, err := search.NewClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
if err != nil {
  // The client can fail to initialize if you pass an invalid parameter.
  panic(err)
}

response, err := client.AddOrUpdateObject(client.NewApiAddOrUpdateObjectRequest(
  "ALGOLIA_INDEX_NAME", "uniqueID", map[string]any{"key": "value"},
))
if err != nil {
  // handle the eventual error
  panic(err)
}
Did you find this page helpful?
Go API clients v4