> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Add or update attributes

> Adds new attributes to a record, or updates existing ones.

**Required ACL:** `addObject`

* If a record with the specified object ID doesn't exist,
  a new record is added to the index **if** `createIfNotExists` is true.
* If the index doesn't exist yet, this method creates a new index.
* Use first-level attributes only. Nested attributes aren't supported.
  If you specify a nested attribute, this operation replaces its first-level ancestor.

To update attributes without replacing the full record, use these built-in operations.
These operations are useful when the initial data isn't available.

* `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. Otherwise, the update is ignored.
  Example: If you pass an `IncrementFrom` value of 2 for the `version` attribute but the current value is 1, the API ignores the update.
  If the object doesn't exist, the API 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. Otherwise, the update is ignored.
  Example: If you pass an `IncrementSet` value of 2 for the `version` attribute and the current value is 1, the API updates the object.
  If the object doesn't exist yet, the API only creates it if you pass an `IncrementSet` value greater than 0.

Specify an operation by providing an object with the attribute to update as the key and its value as an object with these properties:

* `_operation`: the operation to apply on the attribute.
* `value`: the right-hand side argument to the operation, for example, increment or decrement step, or a value to add or remove.

When updating multiple attributes or using multiple operations targeting the same record, use a single partial update for faster processing.

This operation is subject to [indexing rate limits](https://support.algolia.com/hc/articles/4406975251089-Is-there-a-rate-limit-for-indexing-on-Algolia).

## Usage

<CodeGroup>
  ```cs C# theme={"system"}
  // Initialize the client
  var client = new SearchClient(new SearchConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY"));

  // Call the API
  var response = await client.PartialUpdateObjectAsync(
    "<YOUR_INDEX_NAME>",
    "uniqueID",
    new Dictionary<string, string> { { "attributeId", "new value" } }
  );

  // print the response
  Console.WriteLine(response);
  ```

  ```dart Dart theme={"system"}
  // Initialize the client
  final client =
      SearchClient(appId: 'ALGOLIA_APPLICATION_ID', apiKey: 'ALGOLIA_API_KEY');

  // Call the API
  final response = await client.partialUpdateObject(
    indexName: "<YOUR_INDEX_NAME>",
    objectID: "uniqueID",
    attributesToUpdate: {
      'attributeId': "new value",
    },
  );

  // print the response
  print(response);
  ```

  ```go Go theme={"system"}
  // Initialize the client
  client, err := search.NewClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
  if err != nil {
    // The client can fail to initialize if you pass an invalid parameter.
    panic(err)
  }

  // Call the API
  response, err := client.PartialUpdateObject(client.NewApiPartialUpdateObjectRequest(
    "<YOUR_INDEX_NAME>", "uniqueID", map[string]any{"attributeId": "new value"}))
  if err != nil {
    // handle the eventual error
    panic(err)
  }


  // print the response
  print(response)
  ```

  ```java Java theme={"system"}
  // Initialize the client
  SearchClient client = new SearchClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");

  // Call the API
  UpdatedAtWithObjectIdResponse response = client.partialUpdateObject(
    "<YOUR_INDEX_NAME>",
    "uniqueID",
    new HashMap() {
      {
        put("attributeId", "new value");
      }
    }
  );

  // print the response
  System.out.println(response);
  ```

  ```js JavaScript theme={"system"}
  // Initialize the client
  const client = algoliasearch('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');

  // Call the API
  const response = await client.partialUpdateObject({
    indexName: 'theIndexName',
    objectID: 'uniqueID',
    attributesToUpdate: { attributeId: 'new value' },
  });


  // print the response
  console.log(response);
  ```

  ```kotlin Kotlin theme={"system"}
  // Initialize the client
  val client = SearchClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")

  // Call the API
  var response =
    client.partialUpdateObject(
      indexName = "<YOUR_INDEX_NAME>",
      objectID = "uniqueID",
      attributesToUpdate = buildJsonObject { put("attributeId", JsonPrimitive("new value")) },
    )


  // print the response
  println(response)
  ```

  ```php PHP theme={"system"}
  // Initialize the client
  $client = SearchClient::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');

  // Call the API
  $response = $client->partialUpdateObject(
      '<YOUR_INDEX_NAME>',
      'uniqueID',
      ['attributeId' => 'new value',
      ],
  );


  // print the response
  var_dump($response);
  ```

  ```python Python theme={"system"}
  # Initialize the client
  # In an asynchronous context, you can use SearchClient instead, which exposes the exact same methods.
  client = SearchClientSync("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")

  # Call the API
  response = client.partial_update_object(
      index_name="<YOUR_INDEX_NAME>",
      object_id="uniqueID",
      attributes_to_update={
          "attributeId": "new value",
      },
  )


  # print the response
  print(response)
  ```

  ```ruby Ruby theme={"system"}
  # Initialize the client
  client = Algolia::SearchClient.create("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")

  # Call the API
  response = client.partial_update_object("<YOUR_INDEX_NAME>", "uniqueID", {attributeId: "new value"})


  # print the response
  puts(response)
  ```

  ```scala Scala theme={"system"}
  // Initialize the client
  val client = SearchClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")

  // Call the API
  val response = Await.result(
    client.partialUpdateObject(
      indexName = "<YOUR_INDEX_NAME>",
      objectID = "uniqueID",
      attributesToUpdate = JObject(List(JField("attributeId", JString("new value"))))
    ),
    Duration(100, "sec")
  )

  // print the response
  println(response)
  ```

  ```swift Swift theme={"system"}
  // Initialize the client
  let client = try SearchClient(appID: "ALGOLIA_APPLICATION_ID", apiKey: "ALGOLIA_API_KEY")

  // Call the API
  let response = try await client.partialUpdateObject(
      indexName: "<YOUR_INDEX_NAME>",
      objectID: "uniqueID",
      attributesToUpdate: ["attributeId": "new value"]
  )

  // print the response
  print(response)
  ```
</CodeGroup>

<Card icon="folder-code" horizontal="true" title="See the full API reference" arrow="true" href="/doc/rest-api/search/partial-update-object">
  For more details about input parameters
  and response fields.
</Card>
