You can copy (duplicate) indices, including their associated records, settings, synonyms, and rules, within the same Algolia application using both the Algolia dashboard and the API.
To copy an index between two Algolia applications, use the API.
About copying indices
Copying an index duplicates the records and configuration,
including synonyms and rules of an existing index (except the enableReRanking setting).
Copying an index does not create a replica. The new index will be an independent copy.
Provide a scope parameter or command-line option,
to choose what you want to copy: records, settings, synonyms, or rules.
The API keys of the source are merged with the existing keys in the destination index.
Copy indices fully
To copy an index including records, settings, synonyms, and Rules,
use the copyIndex method:
Copy
1
2
3
4
5
6
7
8
9
10
11
<?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
If the source index doesn’t exist, copyIndex creates an empty index with zero records under the new name.
If an index with the new name already exists, the destination index will be overwritten.
To prevent overwriting existing indices,
you can check if an index exists with the indexExists method.
Copy indices partially
To copy parts of an index, use the scope parameter.
For example, to copy only the synonyms and settings between indices, but not records or rules:
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"
If you use the scope parameter, records aren’t copied to the new index.
Existing items of the scope are replaced.
Items belonging to other scopes are preserved.
For example, if you use the settings scope, only the settings are copied to the destination index, keeping the records, synonyms, and rules.
Copying a source index that has replicas copies the index’s data, but not its replicas.
The destination index won’t have replicas.
You can’t copy to a destination index that already has replicas.
Copy indices between different applications
To copy an index between different Algolia applications,
use the AccountClient, which is part of the Algolia API clients,
or use the Algolia CLI.
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)
If you copy an index to a different Algolia application,
the targetIndexmust not exist, or the process fails.
If you want to move an index between Algolia applications,
you can copy it first, and then delete it.
Copy index settings
If you want to copy only an index’s setting to another index, you can use the
Manage index > Copy Settings action in the dashboard,
or the copySettings method of the API clients.