index.replaceAllObjects(arrayobjects)
index.replaceAllObjects(arrayobjects, {
// All the following parameters are optionalsafe: bool,
// + any requestOptions
})
index.replace_all_objects(list | iteratorobjects)
index.replace_all_objects(listobjects, {
// 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.
Replace all records from your index with a new set of records.
The replaceAllObjects method performs these operations:
Copy settings, synonyms, and rules from your original index to a temporary index.
Add your new records to the temporary index.
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.
$client=Algolia\AlgoliaSearch\SearchClient::create('YourApplicationID','YourWriteAPIKey');$objects=/* Fetch your objects */;$index=$client->initIndex('YourIndexName');$index->replaceAllObjects($objects);
1
2
3
4
5
6
7
8
client=Algolia::Search::Client.create('YourApplicationID','YourWriteAPIKey')objects=[# your new objects]index=client.init_index('YourIndexName')index.replace_all_objects(objects)
1
2
3
4
5
6
7
8
9
constclient=algoliasearch('YourApplicationID','YourWriteAPIKey');constobjects=[];// Fetch your objectsconstindex=client.initIndex('YourIndexName');index.replaceAllObjects(objects).then(({objectIDs})=>{console.log(objectIDs);});
1
2
3
4
5
6
client=SearchClient.create("YourApplicationID","YourWriteAPIKey")objects=[]# Fetch your objects
index=client.init_index("YourIndexName")index.replace_all_objects(objects)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
structContact:Encodable{letobjectID:ObjectIDletfirstname:Stringletlastname:String}letclient=SearchClient(appID:"YourApplicationID",apiKey:"YourWriteAPIKey")letindex=client.index(withName:"YourIndexName")letobjects:[Contact]!=[/*Fetch your objects*/]index.replaceAllObjects(with:objects){resultinifcase.success(letresponse)=result{print("Response: \(response)")}}
// With JsonObjectvaljson=listOf(json{"firstname"to"Jimmie""lastname"to"Barninger"},json{"firstname"to"Warren""lastname"to"Speach"})index.replaceAllObjects(json)// With serializable class@Serializabledata classContact(valfirstname:String,vallastname:String)valcontacts=listOf(Contact("Jimmie","Barninger"),Contact("Warren","Speach"))index.replaceAllObjects(Contact.serializer(),contacts)
1
2
3
4
5
varclient=newSearchClient("YourApplicationID","YourWriteAPIKey");varindex=client.InitIndex("YourIndexName");varobjects=/* Fetch your objects */;index.ReplaceAllObjects(objects);
1
2
3
4
5
6
7
8
9
10
11
12
13
SearchClientclient=DefaultSearchClient.create("YourApplicationID","YourWriteAPIKey");SearchIndex<Contact>index=client.initIndex("YourIndexName",Contact.class);// Fetch your objectsList<Contact>objects=newArrayList<>();// Sync versionindex.replaceAllObjects(objects);// Async versionindex.replaceAllObjectsAsync(objects);
1
2
3
4
5
6
7
8
9
10
11
12
packagemainimport"github.com/algolia/algoliasearch-client-go/v3/algolia/search"funcmain(){client:=search.NewClient("YourApplicationID","YourWriteAPIKey")index:=client.InitIndex("YourIndexName")objects:=[]Object{/* Fetch your objects */}res,err:=index.ReplaceAllObjects(objects)}
importalgolia.AlgoliaClientimportalgolia.AlgoliaDsl._importalgolia.responses._importscala.concurrent.duration._importscala.concurrent.duration.FiniteDurationimportscala.concurrent.{Await,ExecutionContext,ExecutionContextExecutor,Future}caseclassMyCaseClass(objectID:String,/* ... */)extendsObjectIDobjectMain{defmain(args:Array[String]):Unit={implicitvalec:ExecutionContextExecutor=ExecutionContext.globalimplicitvalawaitDuration:FiniteDuration=10secondsvalclient=newAlgoliaClient("YourApplicationID","YourWriteAPIKey")valtmpIndexName="atomic_reindex_tmp"valindexName="atomic_reindex"// 1. Copy the settings, synonyms and rules (but not the records)// of the target index into the temporary indexvalcopyTask=Await.result(client.execute(copyindexindexNametotmpIndexNamescopeSeq("settings","synonyms","rules")),awaitDuration)client.execute(waitFortaskcopyTaskfromindexName)// 2. Fetch your data and push it to the temporary indexvalobjects:Seq[MyCaseClass]=Seq(/* ... */)// Here is where you push your data to the temporary indexvalbatchTasks=Await.result(Future.sequence(objects.grouped(1000).map(batch=>client.execute(indexintotmpIndexNameobjectsbatch))),awaitDuration)Await.result(Future.sequence(batchTasks.map(task=>client.execute(waitFortasktaskfromtmpIndexName))),awaitDuration)// 3. Move the temporary index to the target indexclient.execute(moveindextmpIndexNametoindexName)}}
Replace all rexcords and wait for operations
Copy
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,]);
1
2
3
4
5
6
7
8
client=Algolia::Search::Client.create('YourApplicationID','YourWriteAPIKey')objects=[# your new objects]index=client.init_index('YourIndexName')index.replace_all_objects(objects,{safe: true})
1
2
3
4
5
6
7
8
9
constclient=algoliasearch('YourApplicationID','YourWriteAPIKey');constobjects=[];// Fetch your objectsconstindex=client.initIndex('YourIndexName');index.replaceAllObjects(objects,{safe:true}).then(({objectIDs})=>{console.log(objectIDs);});
1
2
3
4
5
6
7
8
client=SearchClient.create('YourApplicationID','YourWriteAPIKey')objects=[]# Fetch your objects
index=client.init_index('YourIndexName')index.replace_all_objects(objects,{'safe':True})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
structContact:Encodable{letobjectID:ObjectIDletfirstname:Stringletlastname:String}letclient=SearchClient(appID:"YourApplicationID",apiKey:"YourWriteAPIKey")letindex=client.index(withName:"YourIndexName")letobjects:[Contact]!=[/*Fetch your objects*/]index.replaceAllObjects(with:objects,safe:true){resultinifcase.success(letresponse)=result{print("Response: \(response)")}}
varclient=newSearchClient("YourApplicationID","YourWriteAPIKey");varindex=client.InitIndex("YourIndexName");varobjects=/* Fetch your objects */;index.ReplaceAllObjects(objects,true);
1
2
3
4
5
6
7
8
9
SearchClientclient=DefaultSearchClient.create("YourApplicationID","YourWriteAPIKey");SearchIndex<Contact>index=client.initIndex("YourIndexName",Contact.class);// Fetch your objectsList<Contact>objects=newArrayList<>();index.replaceAllObjects(objects,true);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
packagemainimport("github.com/algolia/algoliasearch-client-go/v3/algolia/opt""github.com/algolia/algoliasearch-client-go/v3/algolia/search")funcmain(){client:=search.NewClient("YourApplicationID","YourWriteAPIKey")index:=client.InitIndex("YourIndexName")objects:=[]Object{/* Fetch your objects */}res,err:=index.ReplaceAllObjects(objects,opt.Safe(true))}
importalgolia.AlgoliaClientimportalgolia.AlgoliaDsl._importalgolia.responses._importscala.concurrent.duration._importscala.concurrent.duration.FiniteDurationimportscala.concurrent.{Await,ExecutionContext,ExecutionContextExecutor,Future}caseclassMyCaseClass(objectID:String,/* ... */)extendsObjectIDobjectMain{defmain(args:Array[String]):Unit={implicitvalec:ExecutionContextExecutor=ExecutionContext.globalimplicitvalawaitDuration:FiniteDuration=10secondsvalclient=newAlgoliaClient("YourApplicationID","YourWriteAPIKey")valtmpIndexName="atomic_reindex_tmp"valindexName="atomic_reindex"// 1. Copy the settings, synonyms and rules (but not the records)// of the target index into the temporary indexvalcopyTask=Await.result(client.execute(copyindexindexNametotmpIndexNamescopeSeq("settings","synonyms","rules")),awaitDuration)client.execute(waitFortaskcopyTaskfromindexName)// 2. Fetch your data and push it to the temporary indexvalobjects:Seq[MyCaseClass]=Seq(/* ... */)// Here is where you push your data to the temporary indexvalbatchTasks=Await.result(Future.sequence(objects.grouped(1000).map(batch=>client.execute(indexintotmpIndexNameobjectsbatch))),awaitDuration)Await.result(Future.sequence(batchTasks.map(task=>client.execute(waitFortasktaskfromtmpIndexName))),awaitDuration)// 3. Move the temporary index to the target indexclient.execute(moveindextmpIndexNametoindexName)}}
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.