suspend fun IndexcopyIndex(
destination: IndexName,
scopes: List<Scope>? = null,
requestOptions: RequestOptions? = null
): RevisionIndex
suspend fun ClientAccount.copyIndex(
source: Index,
destination: Index
): List<Task>
client.CopyIndex(
StringindexNameSrc,
StringindexNameDest,
// All the following parameters are optionalscope: IEnumerable<String>
)
// Copy index in between apps
client.CopyIndex(
SearchIndexindexNameSrc,
SearchIndexindexNameDest,
)
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.
To copy parts of your source index, use the scope parameter.
If you omit the scope parameter, everything is copied.
For example, to copy an index’s settings and synonyms, but not records and rules,
set the scope parameter to: ["settings", "synonyms"].
The scope is replaced completely.
Different items belonging to the same scope are not merged.
For example, with scope: "settings",
all settings of the destination index are replaced with the settings of the source index.
Items in different scopes are preserved.
If you set the scope parameter, records aren’t copied.
<?phprequire_once__DIR__."/vendor/autoload.php";useAlgolia\AlgoliaSearch\SearchClient;// Use an API key with `addObject` ACL$client=SearchClient::create('YourApplicationID','YourAPIKey');// Copy `indexNameSrc` to `indexNameDest`$client->copyIndex('indexNameSrc','indexNameDest');
1
2
3
4
5
6
7
8
9
require'algolia'# Use an API key with `addObject` ACLclient=Algolia::Search::Client.create('YourApplicationID','YourAPIKey')# Copy `indexNameSrc` to `indexNameDest`client.copy_index('indexNameSrc','indexNameDest')
1
2
3
4
5
6
7
constalgoliasearch=require('algoliasearch');// Use an API key with `addObject` ACLconstclient=algoliasearch('YourApplicationID','YourAPIKey');// Copy `indexNameSrc` to `indexNameDest`client.copyIndex('indexNameSrc','indexNameDest');
1
2
3
4
5
6
7
fromalgoliasearch.search_clientimportSearchClient# Use an API key with `addObject` ACL
client=SearchClient.create("YourApplicationID","YourAPIKey")# Copy `indexNameSrc` to `indexNameDest`
client.copy_index("indexNameSrc","indexNameDest")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
importAlgoliaSearchClient// Use an API key with `addObject` ACLletclient=SearchClient(appID:"YourApplicationID",apiKey:"YourAPIKey")// Copy `indexNameSrc` to `indexNameDest`client.copyIndex(from:"indexNameSrc",to:"indexNameDest"){resultinifcase.success(letresponse)=result{print("Response: \(response)")}}
1
2
3
4
5
6
7
8
// Use an API key with `addObject` ACLvalclient=ClientSearch(ApplicationID("YourApplicationID")APIKey("YourAPIKey"))// Copy `indexNameSrc` to `indexNameDest`valindex=client.initIndex(IndexName("indexNameSrc"))index.copyIndex(IndexName("indexNameDest"))
1
2
3
4
5
6
7
8
// Use an API key with `addObject` ACLvarclient=newSearchClient("YourApplicationID","YourAPIKey");// Copy `indexNameSrc` to `indexNameDest`client.CopyIndex("indexNameSrc","indexNameDest");// Asynchronousawaitclient.CopyIndexAsync("indexNameSrc","indexNameDest");
1
2
3
4
5
6
7
8
// Use an API key with `addObject` ACLSearchClientclient=DefaultSearchClient.create("YourApplicationID","YourAPIKey");// Copy `indexNameSrc` to `indexNameDest`client.copyIndex("indexNameSrc","indexNameDest");// Asynchronousclient.copyIndexAsync("indexNameSrc","indexNameDest");
1
2
3
4
5
// Use an API key with `addObject` ACLclient:=search.NewClient("YourApplicationID","YourAPIKey")// Copy `indexNameSrc` to `indexNameDest`res,err:=client.CopyIndex("indexNameSrc","indexNameDest")
1
2
3
4
5
// Use an API key with `addObject` ACLvalclient=newAlgoliaClient("YourApplicationID","YourAPIKey")// Copy `indexNameSrc` to `indexNameDest`client.execute{copyindex"indexNameSrc"to"indexNameDest"}
1
2
# Copy `INDEX_NAME_SRC` to `INDEX_NAME_DEST`
algolia index copy INDEX_NAME_SRC INDEX_NAME_DEST
Copy parts of an index with scopes
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
<?phprequire_once__DIR__."/vendor/autoload.php";useAlgolia\AlgoliaSearch\SearchClient;// Use an API key with `addObject` ACL$client=SearchClient::create('YourApplicationID','YourAPIKey');// Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`$client->copyIndex('indexNameSrc','indexNameDest',['scope'=>['settings','synonyms']]);
1
2
3
4
5
6
7
8
9
10
11
require'algolia'# Use an API key with `addObject` ACLclient=Algolia::Search::Client.create('YourApplicationID','YourAPIKey')# Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`client.copy_index('indexNameSrc','indexNameDest',{scope: ['settings','synonyms']})
1
2
3
4
// Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`client.copyIndex('indexNameSrc','indexNameDest',{scope:['settings','synonyms']});
1
2
3
4
5
6
7
8
9
fromalgoliasearch.search_clientimportSearchClient# Use an API key with `addObject` ACL
client=SearchClient.create("YourApplicationID","YourAPIKey")# Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`
client.copy_index("indexNameSrc","indexNameDest",{"scope":["settings","synonyms"]})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
importAlgoliaSearchClient// Use an API key with `addObject` ACLletclient=SearchClient(appID:"YourApplicationID",apiKey:"YourAPIKey")// Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`client.copyIndex(from:"indexNameSrc",to:"indexNameDest",scope:[Scope.settings,Scope.synonyms])
1
2
3
4
5
6
7
8
9
10
11
12
13
// Use an API key with `addObject` ACLvalclient=ClientSearch(ApplicationID("YourApplicationID"),APIKey("YourAPIKey"))// Copy only synonyms and settings from `indexNameSrc` to `indexNameDest`valindex=client.initIndex(IndexName("indexNameSrc"))valscopes=listOf(Scope.Settings,Scope.Synonyms)index.copyIndex(IndexName("indexNameDest"),scopes)
1
2
3
4
5
6
7
8
9
10
11
12
13
// Use an API key with `addObject` ACLvarclient=newSearchClient("YourApplicationID","YourAPIKey");// Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`List<string>scopes=newList<string>(){CopyScope.Settings,CopyScope.Synonyms};client.CopyIndex("indexNameSrc","indexNameDest",scope:scopes);// Asynchronousclient.CopyIndexAsync("indexNameSrc","indexNameDest",scope:scopes);
1
2
3
4
5
6
7
8
// Use an API key with `addObject` ACLSearchClientclient=DefaultSearchClient.create("YourApplicationID","YourAPIKey");// Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`client.copyIndex("indexNameSrc","indexNameDest",Arrays.asList("settings","synonyms"));
1
2
3
4
5
6
7
8
9
// Use an API key with `addObject` ACLclient:=search.NewClient("YourApplicationID","YourAPIKey")// Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`res,err:=client.CopyIndex("indexNameSrc","indexNameDest",opt.Scopes("settings","synonyms"),)
1
2
3
4
5
6
7
// Use an API key with `addObject` ACLvalclient=newAlgoliaClient("YourApplicationID","YourAPIKey")// Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`client.execute{copyindex"indexNameSrc"to"indexNameDest"scopesSeq("settings","synonyms")}
1
2
3
# Copy only settings and synonyms from `INDEX_NAME_SRC` to `INDEX_NAME_DEST`
algolia index copy INDEX_NAME_SRC INDEX_NAME_DEST \--scopes"settings,synonyms"
Copy index between apps
Copy
1
2
3
4
5
6
7
8
9
use\Algolia\AlgoliaSearch\SearchClient;use\Algolia\AlgoliaSearch\AccountClient;// Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`$sourceIndex=SearchClient::create('SOURCE_APP_ID','SOURCE_API_KEY')->initIndex('indexNameSrc');$targetIndex=SearchClient::create('TARGET_APP_ID','TARGET_API_KEY')->initIndex('indexNameDest');// This method returns an error if `$targetIndex` existsAccountClient::copyIndex($sourceIndex,$targetIndex);
1
2
3
4
5
6
7
8
9
10
11
12
require'algolia'# Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`source_index=Algolia::Search::Client.create('SOURCE_APP_ID','SOURCE_API_KEY').init_index('indexNameSrc')target_index=Algolia::Search::Client.create('TARGET_APP_ID','TARGET_API_KEY').init_index('indexNameDest')# This method returns an error if `target_index` existsAlgolia::Account::Client.copy_index(source_index,target_index)
1
2
3
4
5
6
7
8
9
10
constalgoliasearch=require('algoliasearch');// Extra package: `npm install @algolia/client-account`constaccountCopyIndex=require('@algolia/client-account').accountCopyIndex;// Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`constsourceIndex=algoliasearch('SOURCE_APP_ID','SOURCE_API_KEY').initIndex('indexNameSrc');consttargetIndex=algoliasearch('TARGET_APP_ID','TARGET_API_KEY').initIndex('indexNameDest');// This method returns an error if `targetIndex` existsaccountCopyIndex(sourceIndex,targetIndex);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
fromalgoliasearch.search_clientimportSearchClientfromalgoliasearch.account_clientimportAccountClient# Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`
source_index=SearchClient.create("SOURCE_APP_ID","SOURCE_API_KEY").init_index("indexNameSrc")target_index=SearchClient.create("TARGET_APP_ID","TARGET_API_KEY").init_index("indexNameDest")# This method throws an exception if `target_index` exists
AccountClient.copy_index(source_index,target_index)
1
2
3
4
5
6
7
8
9
10
11
importAlgoliaSearchClient// Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`letsourceIndex=SearchClient(appID:"SOURCE_APP_ID",apiKey:"SOURCE_API_KEY").index(withName:"indexNameSrc")lettargetIndex=SearchClient(appID:"TARGET_APP_ID",apiKey:"TARGET_API_KEY").index(withName:"indexNameDest")tryAccountClient.copyIndex(source:sourceIndex,destination:targetIndex){resultinifcase.success(letresponse)=result{print("Response: \(response)")}}
1
2
3
4
5
6
7
8
9
10
11
12
13
// Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`valsourceIndex=ClientSearch(ApplicationID("SOURCE_APP_ID"),APIKey("SOURCE_API_KEY")).initIndex(IndexName("indexNameSrc"))valtargetIndex=ClientSearch(ApplicationID("TARGET_APP_ID"),APIKey("TARGET_API_KEY")).initIndex(IndexName("indexNameDest"))// This method throws an exception if `targetIndex` existsClientAccount.copyIndex(sourceIndex,targetIndex)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`SearchClientsourceClient=newSearchClient("SOURCE_APP_ID","SOURCE_API_KEY");SearchClienttargetClient=newSearchClient("TARGET_APP_ID","TARGET_API_KEY");SearchIndexsourceIndex=sourceClient.InitIndex("indexNameSrc");SearchIndextargetIndex=targetClient.InitIndex("indexNameDest");AccountClientaccountClient=newAccountClient();// Provide your 'Record' class for serializing the records during copying// This method throws an exception if `targetIndex` existsaccountClient.CopyIndex<Record>(sourceIndex,targetIndex);// AsynchronousawaitaccountClient.CopyIndexAsync<Record>(sourceIndex,targetIndex);
// Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`SearchClientsourceClient=DefaultSearchClient.create("SOURCE_APP_ID","SOURCE_API_KEY");SearchIndex<Record>sourceIndex=sourceClient.initIndex("indexNameSrc",Record.class);SearchClienttargetClient=DefaultSearchClient.create("TARGET_APP_ID","TARGET_API_KEY");SearchIndex<Record>targetIndex=targetClient.initIndex("indexNameDest",Record.class);AccountClientaccountClient=newAccountClient();// This method throws an exception, if `targetIndex` existsaccountClient.copyIndex(sourceIndex,targetIndex);// AsynchronousaccountClient.copyIndexAsync(sourceIndex,destinationIndex);
1
2
3
4
5
// Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`sourceIndex=search.NewClient("SOURCE_APP_ID","SOURCE_API_KEY").InitIndex("indexNameSrc")targetIndex=search.NewClient("TARGET_APP_ID","TARGET_API_KEY").InitIndex("indexNameDest")res,err:=search.NewAccount().CopyIndex(sourceIndex,targetIndex)
This section shows the JSON response returned by the API.
Each API client encapsulates this response inside objects specific to the programming language,
so that the actual response might be different.
You can view the response by using the getLogs method.
Don’t rely on the order of attributes in the response, as JSON doesn’t guarantee the ordering of keys in objects.