You can copy, or, duplicate whole indices, including records, settings, synonyms, and rules.
You can copy indices within an Algolia application in the dashboard and with the API.
If you want to copy an index between two Algolia applications, you can use the API.
By providing a scope parameter or command-line option,
you can choose what you want to copy: records, settings, synonyms, or rules.
Copying an index has no impact on Analytics, because you can’t copy an index’s analytics data.
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 without arguments:
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 `indexNameSrc` to `indexNameDest`
algolia index copy <indexNameSrc> <indexNameDest>
If an index with the new name already exists, it’s overwritten after the renaming.
To prevent overwriting existing indices,
you can check if an index exists with the indexExists method.
If the source index doesn’t exist, copyIndex creates an empty index with zero records under the new name.
To prevent this, you can also use the indexExists method to see if the source index exists before copying.
Copy indices partially
To copy parts of an index, you can use the scope parameter.
For example, to copy only the synonyms and settings (but not records or Rules) between indices:
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
import AlgoliaSearchClient
// Use an API key with `addObject` ACL
let client = 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
14
// Use an API key with `addObject` ACLvarclient=newSearchClient("YourApplicationID","YourAPIKey");varindex=client.InitIndex("indexNameSrc");// Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`List<CopyScope>scopes=newList<CopyScope>(){CopyScope.SETTINGS,CopyScope.SYNONYMS};index.CopyTo("indexNameDest",scope:scopes);// AsynchronousoriginalIndex.CopyToAsync("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 `indexNameSrc` to `indexNameDest`
algolia index copy <indexNameSrc> <indexNameDest> \--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.
For JavaScript, the AccountClient is distributed as a separate package @algolia/client-account.
You can install it from npm:
Copy
1
npm install @algolia/client-account
Copy
1
2
3
4
5
6
7
8
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');AccountClient::copyIndex($sourceIndex,$targetIndex);
1
2
3
4
5
6
7
8
9
10
11
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')Algolia::Account::Client.copy_index(source_index,target_index)
1
2
3
4
5
6
7
8
constalgoliasearch=require('algoliasearch');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');accountCopyIndex(sourceIndex,targetIndex);
1
2
3
4
5
6
7
8
9
10
11
12
13
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")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
// 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"))ClientAccount.copyIndex(sourceIndex,targetIndex)
1
2
3
4
5
6
7
8
9
10
11
12
// 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");// Serialize records as Contact type during copyAccountClient.CopyIndex<Contact>(sourceIndex,targetIndex);// AsynchronousAccountClient.CopyIndexAsync<Contact>(sourceIndex,destinationIndex);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 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);AccountClient.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.