index.save_objects(Arrayobjects)
index.save_objects(Arrayobjects, Hash opts = {
Boolean auto_generate_object_id_if_not_exist: false
# Any requestOptions
})
# add a single object
index.save_object(Hashobject)
index.save_object(Hashobject, Hash opts = {
Boolean auto_generate_object_id_if_not_exist: false
# Any requestOptions
})
index.saveObjects(arrayobjects)
index.saveObjects(arrayobjects, {
autoGenerateObjectIDIfNotExist: boolean // Any other requestOptions
})
// update a single object
index.saveObject(objectobject)
index.saveObject(objectobject, {
autoGenerateObjectIDIfNotExist: boolean // Any other requestOptions
})
index.saveObjects(List<T>objects)
index.saveObjects(List<T>objects, RequestOptionsrequestOptions)
// Auto generate object ID
index.saveObjects(List<T>objects, boolean true)
// Add a single object
index.saveObject(Tobject)
index.saveObject(Tobject, RequestOptionsrequestOptions)
// Auto generate object ID
index.saveObject(Tobject, boolean true)
index.SaveObjects([]Objectobjects)
index.SaveObjects([]Objectobjects, RequestOptionsrequestOptions)
// Update a single object
index.SaveObject(Objectobject)
index.SaveObject(Objectobject, RequestOptionsrequestOptions)
index into "index_name" objects objects
index into "index_name" objects objects options requestOptions// update a single object
index into "index_name" `object` object
index into "index_name" `object` object options requestOptions
We released a new version of the PHP API client in public beta.
Read the beta documentation for more information.
We released a new version of the JavaScript API client in public beta.
Read the beta documentation for more information.
We released a new version of the Java API client in public beta.
Read the beta documentation for more information.
You’re currently reading the JavaScript API client v4 documentation. Check the migration guide to learn how to upgrade from v3 to v4. You can still access the v3 documentation.
Add new objects to an index or replace existing objects with an updated set of attributes.
The save method is used to redefine the entire set of an object’s attributes (except its objectID). In other words, it fully replaces an existing object.
With saveObjects, you define an object’s full set of attributes.
Attributes not specified will no longer exist.
For example, if an existing object contains the author attribute, but you don’t define it in your update call, it removes the author attribute from that object.
In contrast, when using partialUpdateObjects, you can single out one or more attributes and create or update their content.
If you don’t define an existing attribute in your update call, it doesn’t impact it.
To ensure good performance, saveObjects automatically splits your records into batches of 1,000 objects. If you’re indexing many records and have a stable, high-speed internet connection, you can increase the batch size to send more records per request and shorten your indexing time.
To ensure good performance, saveObjects automatically splits your records into batches of 1,000 objects. If you’re indexing many records and have a stable, high-speed internet connection, you can increase the batch size to send more records per request and shorten your indexing time.
To ensure good performance, saveObjects automatically splits your records into batches of 1,000 objects. If you’re indexing many records and have a stable, high-speed internet connection, you can increase the batch size to send more records per request and shorten your indexing time.
To ensure good performance, saveObjects automatically splits your records into batches of 1,000 objects. If you’re indexing many records and have a stable, high-speed internet connection, you can increase the batch size to send more records per request and shorten your indexing time.
To ensure good performance, saveObjects automatically splits your records into batches of 1,000 objects. If you’re indexing many records and have a stable, high-speed internet connection, you can increase the batch size to send more records per request and shorten your indexing time.
To ensure good performance, saveObjects automatically splits your records into batches of 1,000 objects. If you’re indexing many records and have a stable, high-speed internet connection, you can increase the batch size to send more records per request and shorten your indexing time.
When updating large numbers of objects, or large sizes, be aware of the rate limit. You’ll know you’ve reached the rate limit when you start receiving errors on your indexing operations. To resolve rate limiting errors, you need to wait before sending any further indexing operations.
Saving objects is a single transactional operation.
If there’s an error saving one of your objects, none of the objects are added to your index.
// With JsonObjectvaljson=listOf(ObjectID("myID1")tojson{"firstname"to"Jimmie""lastname"to"Barninger"},ObjectID("myID1")tojson{"firstname"to"Warren""lastname"to"Speach"})index.replaceObjects(json)// With serializable class@Serializabledata classContact(valfirstname:String,vallastname:String,overridevalobjectID:ObjectID):Indexablevalcontacts=listOf(Contact("Jimmie","Barninger",ObjectID("myID")),Contact("Jimmie","Barninger",ObjectID("myID")))index.replaceObjects(Contact.serializer(),contacts)
# Add new records from a new-line delimited JSON file
algolia objects import --file records.ndjson
# Add new records from the command lineecho'{ "objectID": "myID1", "firstName": "Jimmie", "lastName": "Barninger" }\n{ "objectID": "myID2", "firstName": "Warren", "lastName": "Speach" }\n'\
| algolia objects import <INDEX> --file -
# Add new records from a JSON (array) file; format with `jq`cat records.json | jq '.[]' | algolia objects import <INDEX> --file -
// With JsonObjectvaljson=json{"firstname"to"Jimmie""lastname"to"Barninger""city"to"New York"}index.replaceObject(ObjectID("myID"),json)// With serializable class@Serializabledata classContact(valfirstname:String,vallastname:String,valcity:String,overridevalobjectID:ObjectID):Indexablevalcontact=Contact("Jimmie","Barninger","New York",ObjectID("myID"))index.replaceObject(Contact.serializer(),contact)
// With JsonObjectvaljson=json{"firstname"to"Jimmie""lastname"to"Barninger""city"to"New York"}index.replaceObject(ObjectID("myID"),json)// With serializable class@Serializabledata classContact(valfirstname:String,vallastname:String,valcity:String,overridevalobjectID:ObjectID):Indexablevalcontact=Contact("Jimmie","Barninger","New York",ObjectID("myID"))index.replaceObject(Contact.serializer(),contact)
If the objectID doesn’t exist, the engine will create a record
Response
This section shows the JSON response returned by the API. Since each language encapsulates this response inside objects specific to that language or implementation, the actual type in your language might differ from what’s written here. You can view the response in the logs (using the getLogs method).