Skip to main content
This page documents an earlier version of the API client. For the latest version, see Save records.
Required ACL: addObject Adds records to an index or replaces them. If a record doesn’t contain an objectID, Algolia automatically adds it. If you specify an existing objectID, it completely replaces all the attributes except for objectID. To update only some attributes of an existing record, use partialUpdateObjects instead. To add a single record, use the saveObject method. C#, Go, Java, JavaScript, PHP, Python only: To ensure good performance, saveObjects automatically sends batches of 1,000 records. If you’re indexing many records and have a stable, high-speed internet connection, increase the batch size to send more records per request and shorten your indexing time.
When updating large numbers of records, be aware of the rate limitations on these processes and the impact on your analytics data.

Examples

Replace all attributes in existing records

List<Contact> contacts = new List<Contact>
{
    new Contact { ObjectID = "myID1", Firstname = "Jimmie", Lastname = "Barninger" },
    new Contact { ObjectID = "myID2", Firstname = "Warren", Lastname = "Speach" }
};

index.SaveObjects(contacts);

// Asynchronous
await index.SaveObjectsAsync(contacts);

Replace all attributes in a single record

index.SaveObject(new Contact { ObjectID = "myID", Firstname = "Jimmie", Lastname = "Barninger", City = "New York" });

// Asynchronous
await index.SaveObjectAsync(new Contact { ObjectID = "myID", Firstname = "Jimmie", Lastname = "Barninger", City = "New York" });

Replace all attributes in existing records and send extra HTTP headers

List<Contact> contacts = new List<Contact>
{
    new Contact { ObjectID = "myID1", Firstname = "Jimmie", Lastname = "Barninger" },
    new Contact { ObjectID = "myID2", Firstname = "Warren", Lastname = "Speach" }
};

RequestOptions requestOptions = new RequestOptions
{
    Headers = new Dictionary<string,string>{ { "X-Algolia-User-ID", "user123" } }
};

index.SaveObjects(contacts, requestOptions);

// Asynchronous
await index.SaveObjectsAsync(contacts, requestOptions);

Increase the default batch size

var config = new SearchConfig("YourApplicationID", "YourWriteAPIKey")
{
    BatchSize = 999999
};

var client = new SearchClient(config);

Parameters

objects
object[]
required
A list of records to save.
autoGenerateObjectIDIfNotExist
boolean
default:false
saveObjects requires an objectID unless you set autoGenerateObjectIDIfNotExist to true.
  • If the objectID exists, Algolia replaces the record
  • If the objectID is present but doesn’t exist, Algolia creates the record
  • If the objectID isn’t specified and autoGenerateObjectID is false (the default), the engine returns an error.
  • If the objectID isn’t specified and autoGenerateObjectID is true, the engine generates an objectID and returns it in the response.
Ruby only: the parameter name is: auto_generate_object_id_if_not_exist.
objectIDKey
string
PHP only: The objectID is set from the value of the specified key.
requestOptions
object
A mapping of request options.

Response

objectID
string
The objectID of the saved record. This property is only returned when using save object.
objectIDs
list
List of objectIDs of the saved records in order. This property is only returned when using save objects.
taskID
integer
The task ID used with the waitTask method.

Response as JSON

This section shows the JSON response returned by the API. Each API client wraps this response in language-specific objects, so the structure may vary. To view the response, use the getLogs method. Don’t rely on the order of properties—JSON objects don’t preserve key order.

Save records

JSON
{
  "objectIDs": [
    "myObjectID1",
    "myObjectID2"
  ],
  "taskID": 678,
}

Save record

JSON
{
  "objectID": "myObjectID1",
  "taskID": 678,
}
I