Api clients / JavaScript / V3 / Methods

Replace All Objects | JavaScript API Client V3 (Deprecated)

This version of the JavaScript API client has been deprecated in favor of the latest version of the JavaScript API client.

Required API Key: any key with the admin ACL
Method signature
Not implemented yet.
See how to achieve that in the example section

About this method

Clears all objects from your index and replaces them with a new set of objects.

Only your objects are replaced: all settings, synonyms, and query rules are untouched.

This method performs an atomic reindex: it replaces all records in an index without any downtime.

This method uses a temporary index. First, it copies your index’s settings, synonyms, and query rules to the temporary index. Then, it adds the objects you passed to the temporary index. Finally, it replaces your index with the temporary one.

Using this method can significantly increase your indexing operations count. It costs the number of new records + 2 operations (copySettings and moveIndex). For example, replacing all objects of an index with a new set of a million objects costs one million (and two) operations. If you’re on a Free plan, make sure you don’t exceed your record limit. If you’re on a paid plan, be careful of the impact on your operations count.

Behind the scenes, using this method will generate a new, temporary index. If the API key used has restricted index access, the API will return an error when attempting this operation. To fix this, make sure your API key has access to yourIndex and yourIndex_tmp_*.

Examples

Replace all objects

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

$objects = /* Fetch your objects */;

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

Replace all objects and wait for operations

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

$objects = /* Fetch your objects */;

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

Parameters

objects
type: list
Required

A schemaless set of key/value pairs representing index attributes.

safe
type: boolean
default: false
Optional

Whether to wait for indexing operations.

Response

No response.

Did you find this page helpful?