This is documentation for v3 of the PHP API clients, which is not the latest version.
To see the documentation for the latest version, see
PHP v4.
This is documentation for v2 of the Ruby API clients, which is not the latest version.
To see the documentation for the latest version, see
Ruby v3.
This is documentation for v4 of the JavaScript API clients, which is not the latest version.
To see the documentation for the latest version, see
JavaScript v5.
This is documentation for v3 of the Python API clients, which is not the latest version.
To see the documentation for the latest version, see
Python v4.
This is documentation for v8 of the Swift API clients, which is not the latest version.
To see the documentation for the latest version, see
Swift v9.
This is documentation for v2 of the Kotlin API clients, which is not the latest version.
To see the documentation for the latest version, see
Kotlin v3.
This is documentation for v6 of the C# API clients, which is not the latest version.
To see the documentation for the latest version, see
C# v7.
This is documentation for v3 of the Java API clients, which is not the latest version.
To see the documentation for the latest version, see
Java v4.
This is documentation for v3 of the Go API clients, which is not the latest version.
To see the documentation for the latest version, see
Go v4.
This is documentation for v1 of the Scala API clients, which is not the latest version.
To see the documentation for the latest version, see
Scala v2.
index.partialUpdateObjects(arrayobjects)
index.partialUpdateObjects(arrayobjects, {
// All the following parameters are optionalcreateIfNotExists: bool,
// + any requestOptions
})
index.partialUpdateObject(objectobject)
index.partialUpdateObject(objectobject, {
// All the following parameters are optionalcreateIfNotExists: bool,
// + any requestOptions
})
index.PartialUpdateObjects(
IEnumerable<T>objects,
// All the following parameters are optional,createIfNotExists: bool,
requestOptions: RequestOptions
)
// Update a single record
index.PartialUpdateObject(
Tobject,
// All the following parameters are optional,createIfNotExists: bool,
requestOptions: RequestOptions
)
partialUpdate from "index_name" objects objects
partialUpdate from "index_name" objects objects options requestOptions// Update a single record
partialUpdate from "index_name" `object` object
partialUpdate from "index_name" `object` object options requestOptions
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.
Use this method to add or update attributes of one or more records,
without replacing the whole record.
If you provide an objectID that exists in your index,
this method adds or updates the attributes of that record,
without affecting the other attributes.
To replace whole records, use the saveObjects method instead.
If you provide an objectID that doesn’t exist in your index,
this method creates a new record unless the createIfNotExists parameter is false.
If you call this method on an index that doesn’t exist yet,
this method creates a new index.
You can’t partially update nested attributes.
If you specify a nested attribute, this method replaces the first-level ancestor.
To update nested attributes, use the saveObjects method.
To retrieve the record’s data, use the getObjects method.
To update an attribute without pushing the entire record, you can use these built-in operations.
These operations can be helpful if you don’t have access to your initial data.
Increment: increment a numeric attribute
Decrement: decrement a numeric attribute
Add: append a number or string element to an array attribute
Remove: remove all matching number or string elements from an array attribute made of numbers or strings
AddUnique: add a number or string element to an array attribute made of numbers or strings only if it’s not already present
IncrementFrom: increment a numeric integer attribute only if the provided value matches the current value, and otherwise ignore the whole object update. For example, if you pass an IncrementFrom value of 2 for the version attribute, but the current value of the attribute is 1, the engine ignores the update. If the object doesn’t exist, the engine only creates it if you pass an IncrementFrom value of 0.
IncrementSet : increment a numeric integer attribute only if the provided value is greater than the current value, and otherwise ignore the whole object update. For example, if you pass an IncrementSet value of 2 for the version attribute, and the current value of the attribute is 1, the engine updates the object. If the object doesn’t exist yet, the engine only creates it if you pass an IncrementSet value that’s greater than 0.
For Remove and AddUnique: the operation will be silently ignored if the array attribute has any nested object or array.
You can specify an operation by providing an object with the attribute to update as the key and its value being an object with the following properties:
_operation: the operation to apply on the attribute
value: the right-hand side argument to the operation, for example, increment or decrement step, value to add or remove
Only the IncrementFrom and IncrementSet operations guarantee idempotent record updates. The other built-in operations aren’t idempotent and can cause unexpected side-effects, unless you use them in combination with the idempotent operations.
For example, if you’re using the Increment or Decrement operations in a concurrent or multi-threaded environment, you may trigger it more than once and end up with wrong data in your records.
classRecordWithPartialUpdate{privateStringobjectID;privatePartialUpdateOperation<Integer>count;publicRecord(StringobjectID,PartialUpdateOperation<Integer>count){this.objectID=objectID;this.count=count;}// Getters and setters omitted for readability}BatchIndexingResponseres=index.partialUpdateObjects(Collections.singletonList(newRecord("myID",PartialUpdateOperation.Increment(2))));
classRecordWithPartialUpdate{privateStringobjectID;@JsonProperty("_tags")privatePartialUpdateOperation<String>tags;publicRecord(StringobjectID,PartialUpdateOperation<String>tags){this.objectID=objectID;this.tags=tags;}// Getters and setters omitted for readability}BatchIndexingResponseres=index.partialUpdateObjects(Collections.singletonList(newRecord("myID",PartialUpdateOperation.AddUnique("public"))));
Update only if the value matches a numeric attribute
This example updates the version attribute using the IncrementFrom built-in operation. This ensures that this attribute is only incremented if the provided value matches.
classRecordWithPartialUpdate{privateStringobjectID;privatePartialUpdateOperation<Integer>version;publicRecord(StringobjectID,PartialUpdateOperation<Integer>version){this.objectID=objectID;this.version=version;}// Getters and setters omitted for readability}BatchIndexingResponseres=index.partialUpdateObjects(Collections.singletonList(newRecord("myID",PartialUpdateOperation.incrementFrom(2))));
classRecordWithPartialUpdate{privateStringobjectID;privatePartialUpdateOperation<Integer>lastmodified;publicRecord(StringobjectID,PartialUpdateOperation<Integer>lastmodified){this.objectID=objectID;this.lastmodified=lastmodified;}// Getters and setters omitted for readability}BatchIndexingResponseres=index.partialUpdateObjects(Collections.singletonList(newRecord("myID",PartialUpdateOperation.incrementSet(1593431913))));
If true, updating a record with a non-existing objectID creates a new record with the specified attributes.
If false (the objectID doesn’t exist), the update will be ignored. This means that no error will be returned, and the record won’t be updated.
In the Java, JavaScript, Ruby, Python, PHP, and .NET API clients, this parameter defaults to false.
requestOptions
type: key-value pairs
default: ""
Optional
A mapping of request options to send along with the query.
objects âž”
object
An object that matches some or all records.
The object needs to contain an objectID.
If you provide an objectID that doesn’t exist,
the behavior of this method depends on the createIfNotExists parameter.
Response
This section shows the JSON response returned by the API.
Each API client encapsulates this response inside objects specific to the programming language,
so that the actual response might be different.
You can view the response by using the getLogs method.
Don’t rely on the order of attributes in the response, as JSON doesn’t guarantee the ordering of keys in objects.