API Reference / API Methods / Indexing / Replace all objects
Feb. 26, 2019

Replace all objects

Required API Key: any key with the admin ACL
Method signature
$index->replaceAllObjects(array objects);

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

About this method

Push a new set of objects and remove all previous ones. Settings, synonyms and query rules are untouched.

Replace all records in an index without any downtime.

Internally, this method copies the existing index settings, synonyms and query rules and indexes all passed objects. Finally, the existing index is replaced by the temporary one.

Using this method creates new records, and increases your indexing operations count. If you’re on a Free or Community plan, please make sure you have enough records available to execute the operation.

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?