Required API Key: any key with the addObject ACL

Method signature
index.replace_all_objects(list | iterator objects)

index.replace_all_objects(list objects, {
    'safe' => bool
})

About this method # A

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 # A

Replace all records#

1
2
3
4
5
6
client = SearchClient.create("AJ0P3S7DWQ", "••••••••••••••••••••")

objects = [] # Fetch your objects

index = client.init_index("YourIndexName")
index.replace_all_objects(objects)

Replace all rexcords and wait for operations#

1
2
3
4
5
6
7
8
client = SearchClient.create('AJ0P3S7DWQ', '••••••••••••••••••••')

objects = [] # Fetch your objects

index = client.init_index('YourIndexName')
index.replace_all_objects(objects, {
    'safe': True
})

Parameters # A

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 # A

This method doesn't return a response.

Did you find this page helpful?