🎉 Try the public beta of the new docs site at algolia.com/doc-beta! 🎉
API client / Methods / Indexing
Required API Key: any key with the addObject ACL
Method signature
$index->replaceAllObjects(array objects);

$index->replaceAllObjects(array objects, [
  // All the following parameters are optional
  'safe' => bool,
]);

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.

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.

The replaceAllObjects method 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.

This lets you replace all records in an index without downtime. The settings, synonyms, and rules remain unchanged.

If you’re using an API key with index restrictions, make sure it has a access to both YourIndex and YourIndex_tmp, or the operation fails.

Because replaceAllObjects creates a temporary index, it temporarily doubles your record count. To offer flexibility, Algolia doesn’t count the three days with the highest number of records towards your monthly total records. However, if you replace all your records more than three times per month, this counts towards your records usage. If you’re on a legacy plan from before July 2020, the replaceAllObjects method counts two operations: copySettings and moveIndex towards your usage, in addition to the record count.

If there’s an error, the temporary index won’t be deleted.

When replacing large numbers of records, be aware of the rate limitations on these processes and the impact on your analytics data.

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

Parameter Description
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 for the indexing operations to finish before continuing.

requestOptions
type: key-value pairs
Optional

A mapping of requestOptions to send along with the query.

Response

This method doesn't return a response.

Did you find this page helpful?