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

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.

Internally, this method uses a temporary index,
where it copies the existing index’s 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?