Guides / Sending and managing data / Manage indices and apps / Manage indices

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.

  • Copying an index doesn’t copy the associated analytics data.

  • Copying indices is resource-intensive and is rate-limited.

Copy indices in the Algolia dashboard

  1. Go to the Algolia dashboard and select your Algolia application.
  2. On the left sidebar, select Search.
  3. Select your Algolia index:

    Select your Algolia application and index

  4. Select Manage index > Duplicate.

    Duplicate your index, including settings, Rules, and synonyms.

  5. Select Create a new index or Overwrite an existing index and enter the name of the destination index.

  6. If you’re overwriting an existing index, enter DUPLICATE to confirm.

  7. Click Duplicate.

Copy indices with the API

To copy indices, use one of these methods:

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:

1
2
3
4
5
6
7
8
9
10
11
<?php
require_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');
  • 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:

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
require_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']
]);

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.

For more information, see Scopes.

Indices with replicas

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.

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` exists
AccountClient::copyIndex($sourceIndex, $targetIndex);

If you copy an index to a different Algolia application, the targetIndex must 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.

Did you find this page helpful?