index.replaceAllObjects(arrayobjects)
index.replaceAllObjects(arrayobjects, {
// All the following parameters are optionalsafe: bool,
// + any requestOptions
})
index.replace_all_objects(listobjects)
index.replace_all_objects(listobjects, {
// All the following parameters are optional
'safe' => bool
})
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.
Clears all objects from your index and replaces them with a new set of objects.
Only your objects are replaced: settings, synonyms, and query rules aren’t modified. This method replaces all records in an index without any downtime.
Behind the scenes, replaceAllObjects uses a temporary index and:
Copies your index’s settings, synonyms, and query rules to the temporary index
Adds your objects to the temporary index
Replaces your index with the temporary one.
If the API key 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 yourIndexandyourIndex_tmp_*.
Using this method can significantly increase your indexing operations and record 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. Because your main and temporary index both have one million records, your application will temporarily host two million records. Make sure you don’t exceed your record limit, and be careful of the impact on your operations count.
$client=Algolia\AlgoliaSearch\SearchClient::create('AJ0P3S7DWQ','••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb');$objects=/* Fetch your objects */;$index=$client->initIndex('your_index_name');$index->replaceAllObjects($objects);
1
2
3
4
5
6
7
8
client=Algolia::Search::Client.create('AJ0P3S7DWQ','••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb')objects=[# your new objects]index=client.init_index('your_index_name')index.replace_all_objects(objects)
1
2
3
4
5
6
7
8
9
constclient=algoliasearch('AJ0P3S7DWQ','••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb');constobjects=[];// Fetch your objectsconstindex=client.initIndex('your_index_name');index.replaceAllObjects(objects).then(({objectIDs})=>{console.log(objectIDs);});
1
2
3
4
5
6
client=SearchClient.create('AJ0P3S7DWQ','••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb')objects=[]# Fetch your objects
index=client.init_index('your_index_name')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:"AJ0P3S7DWQ",apiKey:"••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb")letindex=client.index(withName:"your_index_name")letobjects:[Contact]!=[/*Fetch your objects*/]index.replaceAllObjects(with:objects){resultinifcase.success(letresponse)=result{print("Response: \(response)")}}
1
2
3
4
5
varclient=newSearchClient("AJ0P3S7DWQ","••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb");varindex=client.InitIndex("your_index_name");varobjects=/* Fetch your objects */;index.ReplaceAllObjects(objects);
1
2
3
4
5
6
7
8
9
10
11
12
13
SearchClientclient=DefaultSearchClient.create("AJ0P3S7DWQ","••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb");SearchIndex<Contact>index=client.initIndex("your_index_name",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("AJ0P3S7DWQ","••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb")index:=client.InitIndex("your_index_name")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("AJ0P3S7DWQ","••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb")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)}}
// 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)
$client=Algolia\AlgoliaSearch\SearchClient::create('AJ0P3S7DWQ','••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb');$objects=/* Fetch your objects */;$index=$client->initIndex('your_index_name');$index->replaceAllObjects($objects,['safe'=>true,]);
1
2
3
4
5
6
7
8
client=Algolia::Search::Client.create('AJ0P3S7DWQ','••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb')objects=[# your new objects]index=client.init_index('your_index_name')index.replace_all_objects(objects,{safe: true})
1
2
3
4
5
6
7
8
9
constclient=algoliasearch('AJ0P3S7DWQ','••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb');constobjects=[];// Fetch your objectsconstindex=client.initIndex('your_index_name');index.replaceAllObjects(objects,{safe:true}).then(({objectIDs})=>{console.log(objectIDs);});
1
2
3
4
5
6
7
8
client=SearchClient.create('AJ0P3S7DWQ','••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb')objects=[]# Fetch your objects
index=client.init_index('your_index_name')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:"AJ0P3S7DWQ",apiKey:"••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb")letindex=client.index(withName:"your_index_name")letobjects:[Contact]!=[/*Fetch your objects*/]index.replaceAllObjects(with:objects,safe:true){resultinifcase.success(letresponse)=result{print("Response: \(response)")}}
1
2
3
4
5
varclient=newSearchClient("AJ0P3S7DWQ","••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb");varindex=client.InitIndex("your_index_name");varobjects=/* Fetch your objects */;index.ReplaceAllObjects(objects,true);
1
2
3
4
5
6
7
8
9
SearchClientclient=DefaultSearchClient.create("AJ0P3S7DWQ","••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb");SearchIndex<Contact>index=client.initIndex("your_index_name",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("AJ0P3S7DWQ","••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb")index:=client.InitIndex("your_index_name")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("AJ0P3S7DWQ","••••••••••••••••••••ce1181300d403d21311d5bca9ef1e6fb")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)}}