When copying indices within the same Algolia application,
the destination index is replaced if it exists.You can’t copy an index between two Algolia applications,
if the destination index exists.Everything apart from the analytics data is replaced.
You can’t copy to a destination index that already has replicas.
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 aren’t 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.
// Use an API key with `addObject` ACLvar client = new SearchClient("YourApplicationID", "YourAPIKey");// Copy `indexNameSrc` to `indexNameDest`client.CopyIndex("indexNameSrc", "indexNameDest");// Asynchronousawait client.CopyIndexAsync("indexNameSrc", "indexNameDest");
// Use an API key with `addObject` ACLclient := search.NewClient("YourApplicationID", "YourAPIKey")// Copy `indexNameSrc` to `indexNameDest`res, err := client.CopyIndex("indexNameSrc", "indexNameDest")
// Use an API key with `addObject` ACLSearchClient client = DefaultSearchClient.create("YourApplicationID", "YourAPIKey");// Copy `indexNameSrc` to `indexNameDest`client.copyIndex("indexNameSrc", "indexNameDest");// Asynchronousclient.copyIndexAsync("indexNameSrc", "indexNameDest");
const algoliasearch = require('algoliasearch');// Use an API key with `addObject` ACLconst client = algoliasearch('YourApplicationID', 'YourAPIKey');// Copy `indexNameSrc` to `indexNameDest`client.copyIndex('indexNameSrc', 'indexNameDest');
// Use an API key with `addObject` ACLval client = ClientSearch( ApplicationID("YourApplicationID") APIKey("YourAPIKey"))// Copy `indexNameSrc` to `indexNameDest`val index = client.initIndex(IndexName("indexNameSrc"))index.copyIndex(IndexName("indexNameDest"))
<?phprequire_once __DIR__."/vendor/autoload.php";use Algolia\AlgoliaSearch\SearchClient;// Use an API key with `addObject` ACL$client = SearchClient::create( 'YourApplicationID', 'YourAPIKey');// Copy `indexNameSrc` to `indexNameDest`$client->copyIndex('indexNameSrc', 'indexNameDest');
from algoliasearch.search_client import SearchClient# Use an API key with `addObject` ACLclient = SearchClient.create("YourApplicationID", "YourAPIKey")# Copy `indexNameSrc` to `indexNameDest`client.copy_index("indexNameSrc", "indexNameDest")
require 'algolia'# Use an API key with `addObject` ACLclient = Algolia::Search::Client.create( 'YourApplicationID', 'YourAPIKey')# Copy `indexNameSrc` to `indexNameDest`client.copy_index('indexNameSrc', 'indexNameDest')
// Use an API key with `addObject` ACLval client = new AlgoliaClient("YourApplicationID", "YourAPIKey")// Copy `indexNameSrc` to `indexNameDest`client.execute { copy index "indexNameSrc" to "indexNameDest" }
import AlgoliaSearchClient// Use an API key with `addObject` ACLlet client = SearchClient( appID: "YourApplicationID", apiKey: "YourAPIKey")// Copy `indexNameSrc` to `indexNameDest`client.copyIndex(from: "indexNameSrc", to: "indexNameDest") { result in if case .success(let response) = result { print("Response: \(response)") }}
// Use an API key with `addObject` ACLvar client = new SearchClient("YourApplicationID", "YourAPIKey");// Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`List<string> scopes = new List<string>() { CopyScope.Settings, CopyScope.Synonyms};client.CopyIndex("indexNameSrc","indexNameDest",scope: scopes);// Asynchronousclient.CopyIndexAsync("indexNameSrc","indexNameDest",scope: scopes);
// 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"),)
// Use an API key with `addObject` ACLSearchClient client = DefaultSearchClient.create("YourApplicationID", "YourAPIKey");// Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`client.copyIndex( "indexNameSrc", "indexNameDest", Arrays.asList("settings", "synonyms"));
// Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`client.copyIndex('indexNameSrc', 'indexNameDest', { scope: ['settings', 'synonyms']});
// Use an API key with `addObject` ACLval client = ClientSearch( ApplicationID("YourApplicationID"), APIKey("YourAPIKey"))// Copy only synonyms and settings from `indexNameSrc` to `indexNameDest`val index = client.initIndex(IndexName("indexNameSrc"))val scopes = listOf( Scope.Settings, Scope.Synonyms)index.copyIndex(IndexName("indexNameDest"), scopes)```php PHP<?phprequire_once __DIR__."/vendor/autoload.php";use Algolia\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']]);
from algoliasearch.search_client import SearchClient# Use an API key with `addObject` ACLclient = SearchClient.create("YourApplicationID", "YourAPIKey")# Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`client.copy_index("indexNameSrc", "indexNameDest", { "scope": ["settings", "synonyms"]})
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']})
// Use an API key with `addObject` ACLval client = new AlgoliaClient("YourApplicationID", "YourAPIKey")// Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`client.execute { copy index "indexNameSrc" to "indexNameDest" scopes Seq("settings", "synonyms")}
import AlgoliaSearchClient// Use an API key with `addObject` ACLlet 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])
// Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`SearchClient sourceClient = new SearchClient("SOURCE_APP_ID", "SOURCE_API_KEY");SearchClient targetClient = new SearchClient("TARGET_APP_ID", "TARGET_API_KEY");SearchIndex sourceIndex = sourceClient.InitIndex("indexNameSrc");SearchIndex targetIndex = targetClient.InitIndex("indexNameDest");AccountClient accountClient = new AccountClient();// Provide your 'Record' class for serializing the records during copying// This method throws an exception if `targetIndex` existsaccountClient.CopyIndex<Record>(sourceIndex, targetIndex);// Asynchronousawait accountClient.CopyIndexAsync<Record>(sourceIndex, targetIndex);
// 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)
// Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`SearchClient sourceClient = DefaultSearchClient.create("SOURCE_APP_ID", "SOURCE_API_KEY");SearchIndex<Record> sourceIndex = sourceClient.initIndex("indexNameSrc", Record.class);SearchClient targetClient =DefaultSearchClient.create("TARGET_APP_ID", "TARGET_API_KEY");SearchIndex<Record> targetIndex = targetClient.initIndex("indexNameDest", Record.class);AccountClient accountClient = new AccountClient();// This method throws an exception, if `targetIndex` existsaccountClient.copyIndex(sourceIndex, targetIndex);// AsynchronousaccountClient.copyIndexAsync(sourceIndex, destinationIndex);
const algoliasearch = require('algoliasearch');// Extra package: `npm install @algolia/client-account`const accountCopyIndex = require('@algolia/client-account').accountCopyIndex;// Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`const sourceIndex = algoliasearch('SOURCE_APP_ID', 'SOURCE_API_KEY').initIndex('indexNameSrc');const targetIndex = algoliasearch('TARGET_APP_ID', 'TARGET_API_KEY').initIndex('indexNameDest');// This method returns an error if `targetIndex` existsaccountCopyIndex(sourceIndex, targetIndex);
// Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`val sourceIndex = ClientSearch( ApplicationID("SOURCE_APP_ID"), APIKey("SOURCE_API_KEY")).initIndex(IndexName("indexNameSrc"))val targetIndex = ClientSearch( ApplicationID("TARGET_APP_ID"), APIKey("TARGET_API_KEY")).initIndex(IndexName("indexNameDest"))// This method throws an exception if `targetIndex` existsClientAccount.copyIndex(sourceIndex, targetIndex)
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);
from algoliasearch.search_client import SearchClientfrom algoliasearch.account_client import AccountClient# 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` existsAccountClient.copy_index(source_index, target_index)
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)
import AlgoliaSearchClient// Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`let sourceIndex = SearchClient(appID: "SOURCE_APP_ID", apiKey: "SOURCE_API_KEY").index(withName: "indexNameSrc")let targetIndex = SearchClient(appID: "TARGET_APP_ID", apiKey: "TARGET_API_KEY").index(withName: "indexNameDest")try AccountClient.copyIndex(source: sourceIndex, destination: targetIndex) { result in if case .success(let response) = result { print("Response: \(response)") }}
This is the taskID which is used with the waitTask method.Note: You can use either the source or destination index to
wait on the resulting taskID. In either case, the wait will include
the full copy process.
This section shows the JSON response returned by the API.
Each API client wraps this response in language-specific objects, so the structure may vary.
To view the response, use the getLogs method.
Don’t rely on the order of properties—JSON objects don’t preserve key order.