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

# Replace all records

> Replaces all records in an index with new ones.

**Required ACL:** `addObject`, `deleteIndex` (optional, for cleanup after a failed operation)

This helper method replaces all records in an index without interrupting ongoing searches.

It combines [batch](/doc/rest-api/search/batch) and [copy/move index](/doc/rest-api/search/operation-index) operations:

1. Copy settings, synonyms, and rules to a temporary index.
2. Add the records from the `objects` parameter to the temporary index.
3. Replace the original index with the temporary one.

Notes:

* If your API key restricts access to specific indices, make sure it also grants access to the temporary index `INDEX_NAME_tmp_*`. Replace `INDEX_NAME` with the name of your original index.

* This method creates a temporary index, so your record count can temporarily double during the operation.
  Algolia doesn't count the three days with the highest number of records towards usage.

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

* If the operation fails, the original index isn't replaced.
  The client can delete the temporary index only if your API key has the `deleteIndex` ACL.

The response includes the results of the individual API requests.

## Usage

<CodeGroup>
  ```cs C# theme={"system"}
  var response = await client.ReplaceAllObjectsAsync(
    "INDEX_NAME",
    new List<Object>
    {
      new Dictionary<string, string> { { "objectID", "1" }, { "name", "Adam" } },
      new Dictionary<string, string> { { "objectID", "2" }, { "name", "Benoit" } },
    },
    77,
    new List<ScopeType> { Enum.Parse<ScopeType>("Settings"), Enum.Parse<ScopeType>("Synonyms") }
  );
  ```

  ```go Go theme={"system"}
  response, err := client.ReplaceAllObjects(
    "INDEX_NAME",
    []map[string]any{{"objectID": "1", "name": "Adam"}, {"objectID": "2", "name": "Benoit"}}, search.WithBatchSize(77), search.WithScopes(
      []search.ScopeType{search.ScopeType("settings"), search.ScopeType("synonyms")}))
  if err != nil {
    // handle the eventual error
    panic(err)
  }
  ```

  ```java Java theme={"system"}
  ReplaceAllObjectsResponse response = client.replaceAllObjects(
    "INDEX_NAME",
    Arrays.asList(
      new HashMap() {
        {
          put("objectID", "1");
          put("name", "Adam");
        }
      },
      new HashMap() {
        {
          put("objectID", "2");
          put("name", "Benoit");
        }
      }
    ),
    77,
    Arrays.asList(ScopeType.SETTINGS, ScopeType.SYNONYMS)
  );
  ```

  ```js JavaScript theme={"system"}
  const response = await client.replaceAllObjects({
    indexName: 'cts_e2e_replace_all_objects_scopes_javascript',
    objects: [
      { objectID: '1', name: 'Adam' },
      { objectID: '2', name: 'Benoit' },
    ],
    batchSize: 77,
    scopes: ['settings', 'synonyms'],
  });
  ```

  ```kotlin Kotlin theme={"system"}
  var response =
    client.replaceAllObjects(
      indexName = "INDEX_NAME",
      objects =
        listOf(
          buildJsonObject {
            put("objectID", JsonPrimitive("1"))
            put("name", JsonPrimitive("Adam"))
          },
          buildJsonObject {
            put("objectID", JsonPrimitive("2"))
            put("name", JsonPrimitive("Benoit"))
          },
        ),
      batchSize = 77,
      scopes =
        listOf(
          ScopeType.entries.first { it.value == "settings" },
          ScopeType.entries.first { it.value == "synonyms" },
        ),
    )
  ```

  ```php PHP theme={"system"}
  $response = $client->replaceAllObjects(
      'INDEX_NAME',
      [
          ['objectID' => '1',
              'name' => 'Adam',
          ],

          ['objectID' => '2',
              'name' => 'Benoit',
          ],
      ],
      77,
      [
          'settings',

          'synonyms',
      ],
  );
  ```

  ```python Python theme={"system"}
  response = client.replace_all_objects(
      index_name="INDEX_NAME",
      objects=[
          {
              "objectID": "1",
              "name": "Adam",
          },
          {
              "objectID": "2",
              "name": "Benoit",
          },
      ],
      batch_size=77,
      scopes=[
          "settings",
          "synonyms",
      ],
  )
  ```

  ```ruby Ruby theme={"system"}
  response = client.replace_all_objects(
    "INDEX_NAME",
    [{objectID: "1", name: "Adam"}, {objectID: "2", name: "Benoit"}],
    77,
    ["settings", "synonyms"]
  )
  ```

  ```scala Scala theme={"system"}
  val response = Await.result(
    client.replaceAllObjects(
      indexName = "INDEX_NAME",
      objects = Seq(
        JObject(List(JField("objectID", JString("1")), JField("name", JString("Adam")))),
        JObject(List(JField("objectID", JString("2")), JField("name", JString("Benoit"))))
      ),
      batchSize = 77,
      scopes = Some(Seq(ScopeType.withName("settings"), ScopeType.withName("synonyms")))
    ),
    Duration(100, "sec")
  )
  ```

  ```swift Swift theme={"system"}
  let response = try await client.replaceAllObjects(
      indexName: "INDEX_NAME",
      objects: [["objectID": "1", "name": "Adam"], ["objectID": "2", "name": "Benoit"]],
      batchSize: 77,
      scopes: [ScopeType.settings, ScopeType.synonyms]
  )
  ```
</CodeGroup>

## Parameters

<Tabs>
  <Tab title="C#">
    <ParamField body="indexName" type="string" required>
      Name of the index in which to replace records.
    </ParamField>

    <ParamField body="objects" type="IEnumerable<T>" required>
      Records that replace the existing records in your index.
    </ParamField>

    <ParamField body="T" type="type parameter" required>
      The model of your index's records.
    </ParamField>

    <ParamField body="batchSize" type="int" default={1000}>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="scopes" type="List<ScopeType>" required>
      Scopes to include in the replacement operation.
      Use one or more `ScopeType` values.
      For the allowed values, see [Scope types](/doc/rest-api/search/operation-index#body-scope).
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>

    <ParamField body="cancellationToken" type="CancellationToken" default="default">
      Parameter that can be used as a signal to cancel this request.
    </ParamField>
  </Tab>

  <Tab title="Go">
    <ParamField body="indexName" type="string" required>
      Name of the index in which to replace records.
    </ParamField>

    <ParamField body="objects" type="[]map[string]any" required>
      Records that replace the existing records in your index.
    </ParamField>

    <ParamField body="opts..." type="ReplaceAllObjectsOption">
      Functional options to provide extra arguments.

      <Expandable title="available functions">
        <ParamField body="search.WithScopes" type="function">
          **Signature:** `func(scopes []ScopeType) replaceAllObjectsOption`

          Scopes to include in the replacement operation.
          Use one or more `ScopeType` values.
          For the allowed values, see [Scope types](/doc/rest-api/search/operation-index#body-scope).
        </ParamField>

        <ParamField body="search.WithBatchSize" type="function">
          **Signature:** `func(batchSize int) chunkedBatchOption`

          Number of records to process in one batch.
          The default batch size is 1,000.
        </ParamField>

        <ParamField body="search.WithWaitForTasks" type="function">
          **Signature:** `func(withWaitForTasks bool) chunkedBatchOption`

          Whether to wait until all batch requests are done.
        </ParamField>

        <ParamField body="search.WithHeaderParam" type="function">
          **Signature:** `func(key string, value string) requestOption`

          Sets extra header parameters for this request.
          To learn more, see [request options](/doc/libraries/sdk/request-options).
        </ParamField>

        <ParamField body="search.WithQueryParam" type="function">
          **Signature:** `func(key string, value string) requestOption`

          Sets extra query parameters for this request.
          To learn more, see [request options](/doc/libraries/sdk/request-options).
        </ParamField>
      </Expandable>
    </ParamField>
  </Tab>

  <Tab title="Java">
    <ParamField body="indexName" type="String" required>
      Name of the index in which to replace records.
    </ParamField>

    <ParamField body="objects" type="Iterable<T>" required>
      Records that replace the existing records in your index.
    </ParamField>

    <ParamField body="T" type="Type parameter" required>
      The model of your index's records.
    </ParamField>

    <ParamField body="batchSize" type="int" required>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="scopes" type="List<ScopeType>" required>
      Scopes to include in the replacement operation.
      Use one or more `ScopeType` values.
      For the allowed values, see [Scope types](/doc/rest-api/search/operation-index#body-scope).
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="JavaScript">
    <ParamField body="indexName" type="string" required>
      Name of the index in which to replace records.
    </ParamField>

    <ParamField body="objects" type="Record<string,unknown>[]" required>
      Records that replace the existing records in your index.
    </ParamField>

    <ParamField body="batchSize" type="number" default={1000}>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="scopes" type="string[]" required>
      Scopes to include in the replacement operation.
      Use one or more `ScopeType` values.
      For the allowed values, see [Scope types](/doc/rest-api/search/operation-index#body-scope).
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Kotlin">
    <ParamField body="indexName" type="String" required>
      Name of the index in which to replace records.
    </ParamField>

    <ParamField body="objects" type="List<JsonObject>" required>
      Records that replace the existing records in your index.
    </ParamField>

    <ParamField body="batchSize" type="Int" default={1000}>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="scopes" type="List<ScopeType>" required>
      Scopes to include in the replacement operation.
      Use one or more `ScopeType` values.
      For the allowed values, see [Scope types](/doc/rest-api/search/operation-index#body-scope).
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="PHP">
    <ParamField body="indexName" type="string" required>
      Name of the index in which to replace records.
    </ParamField>

    <ParamField body="objects" type="array" required>
      Records that replace the existing records in your index.
    </ParamField>

    <ParamField body="batchSize" type="int" default={1000}>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="scopes" type="array" required>
      Scopes to include in the replacement operation.
      Use one or more `ScopeType` values.
      For the allowed values, see [Scope types](/doc/rest-api/search/operation-index#body-scope).
    </ParamField>

    <ParamField body="requestOptions" type="array">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Python">
    <ParamField body="index_name" type="str" required>
      Name of the index in which to replace records.
    </ParamField>

    <ParamField body="objects" type="list[dict]" required>
      Records that replace the existing records in your index.
    </ParamField>

    <ParamField body="batch_size" type="int" default={1000}>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="scopes" type="list[str]" required>
      Scopes to include in the replacement operation.
      Use one or more `ScopeType` values.
      For the allowed values, see [Scope types](/doc/rest-api/search/operation-index#body-scope).
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Ruby">
    <ParamField body="index_name" type="String" required>
      Name of the index in which to replace records.
    </ParamField>

    <ParamField body="objects" type="Array[Hash]" required>
      Records that replace the existing records in your index.
    </ParamField>

    <ParamField body="batchSize" type="Integer" default={1000}>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="scopes" type="Array[String]" required>
      Scopes to include in the replacement operation.
      Use one or more `ScopeType` values.
      For the allowed values, see [Scope types](/doc/rest-api/search/operation-index#body-scope).
    </ParamField>

    <ParamField body="requestOptions" type="Hash">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Scala">
    <ParamField body="indexName" type="String" required>
      Name of the index in which to replace records.
    </ParamField>

    <ParamField body="objects" type="Seq[JObject]" required>
      Records that replace the existing records in your index.
    </ParamField>

    <ParamField body="batchSize" type="Int" default={1000}>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="scopes" type="Seq[ScopeType]">
      Scopes to include in the replacement operation.
      Use one or more `ScopeType` values.
      For the allowed values, see [Scope types](/doc/rest-api/search/operation-index#body-scope).
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Swift">
    <ParamField body="indexName" type="String" required>
      Name of the index in which to replace records.
    </ParamField>

    <ParamField body="objects" type="[Encodable]" required>
      Records that replace the existing records in your index.
    </ParamField>

    <ParamField body="batchSize" type="Int" default={1000}>
      Number of records to process in one batch.
    </ParamField>

    <ParamField body="scopes" type="[ScopeType]">
      Scopes to include in the replacement operation.
      Use one or more `ScopeType` values.
      For the allowed values, see [Scope types](/doc/rest-api/search/operation-index#body-scope).
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>
</Tabs>
