index.save_objects(Arrayobjects)
index.save_objects(Arrayobjects, Hash opts = {
Boolean auto_generate_object_id_if_not_exist: false
# Any requestOptions
})
# Add a single record
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 record
index.saveObject(objectobject)
index.saveObject(objectobject, {
autoGenerateObjectIDIfNotExist: boolean // Any other requestOptions
})
index.saveObjects(List<T>objects)
index.saveObjects(List<T>objects, RequestOptionsrequestOptions)
// Auto-generate objectID
index.saveObjects(List<T>objects, boolean true)
// Add a single record
index.saveObject(Tobject)
index.saveObject(Tobject, RequestOptionsrequestOptions)
// Auto-generate objectID
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 record
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.
With saveObjects, you define a record’s complete set of attributes.
Attributes not specified will no longer exist.
For example, if an existing record contains the author attribute, but you don’t define it in your update call, it removes the author attribute from that record.
With 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 affect it.
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, you can increase the batch size to send more records per request and shorten your indexing time.
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, you can increase the batch size to send more records per request and shorten your indexing time.
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, you can increase the batch size to send more records per request and shorten your indexing time.
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, you can increase the batch size to send more records per request and shorten your indexing time.
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, you can increase the batch size to send more records per request and shorten your indexing time.
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, you can increase the batch size to send more records per request and shorten your indexing time.
When updating large numbers of records, or large records, be aware of the rate limit of 10,000 indexing operations per Unit (as applicable). 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.
// 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)
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.
In the Ruby API client, this parameter is spelled: auto_generate_object_id_if_not_exist.
objectIDKey
type: string
Optional
The objectID is set from the value of the specified key.
Only available for PHP.
requestOptions
type: key-value mapping
default: No request options
Optional
A mapping of requestOptions to send along with the query. In addition to sending extra HTTP headers or setting timeouts, you can use requestOptions to set autoGenerateObjectIDIfNotExist.
objects âž”
object
An objectID must be specified for each record.
If the objectID exists, the record is replaced
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).