Required API Key: any key with the addObject ACL

Method signature
$index->replaceAllObjects(array objects);

$index->replaceAllObjects(array objects, [
  'safe' => bool,
]);

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.

You’re currently reading the Ruby API client v2 documentation. Check the migration guide to learn how to upgrade from v1 to v2. You can still access the v1 documentation.

About this method

Replace all records from your index with a new set of records.

This method lets you replace all records in your index without downtime. It performs these operations:

  1. Copy settings, synonyms, and rules from your original index to a temporary index.
  2. Add your new records to the temporary index.
  3. Replace your original index with the temporary index.
  • Use the safe parameter to ensure that these (asynchronous) operations are performed in sequence.

  • If there’s an error duing one of these steps, the temporary index won’t be deleted.

  • This operation is rate-limited.

  • This method creates a temporary index: your record count is temporarily doubled. Algolia doesn’t count the three days with the highest number of records towards your monthly usage.

  • If you’re on a legacy plan (before July 2020), this method counts two operations towards your usage (in addition to the number of records): copySettings and moveIndex.

  • The API key you use for this operation must have access to the index YourIndex and the temporary index YourIndex_tmp.

Examples

Read the Algolia CLI documentation for more information.

Replace all records

1
2
3
4
5
6
7
8
9
$client = Algolia\AlgoliaSearch\SearchClient::create(
  'YourApplicationID',
  'YourWriteAPIKey'
);

$objects = /* Fetch your objects */;

$index = $client->initIndex('YourIndexName');
$index->replaceAllObjects($objects);

Replace all rexcords and wait for operations

1
2
3
4
5
6
7
8
9
10
11
$client = Algolia\AlgoliaSearch\SearchClient::create(
  'YourApplicationID',
  'YourWriteAPIKey'
);

$objects = /* Fetch your objects */;

$index = $client->initIndex('YourIndexName');
$index->replaceAllObjects($objects, [
  'safe' => true,
]);

Parameters

objects
type: list
Required

List of records.

Use an iterator instead of a list to prevent memory issues, especially if you want to replace many records.

safe
type: boolean
default: false
Optional

If true, wait after each step before continuing.

requestOptions
type: key-value pairs
Optional

A mapping of request options to send along with the query.

Response

This method doesn't return a response.

Did you find this page helpful?