This page documents an earlier version of the API client. For the latest version, see Save records.
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
Replace all attributes in a single record
Replace all attributes in existing records and send extra HTTP headers
Increase the default batch size
Parameters
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 andautoGenerateObjectID
isfalse
(the default), the engine returns an error. - If the
objectID
isn’t specified andautoGenerateObjectID
istrue
, the engine generates anobjectID
and returns it in the response.
auto_generate_object_id_if_not_exist
.PHP only: The
objectID
is set from the value of the specified key.A mapping of request options.
Response
The objectID of the saved record. This property is only returned when using save object.
List of objectIDs of the saved records in order. This property is only returned when using save objects.
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 thegetLogs
method.
Don’t rely on the order of properties—JSON objects don’t preserve key order.
Save records
JSON
Save record
JSON