API Reference / API Methods / Manage indices / Copy index
Required API Key: any key with the addObject ACL
Method signature
$client->copyIndex(
  string indexNameSrc,
  string indexNameDest
)
$client->copyIndex(
  string indexNameSrc,
  string indexNameDest,
  [
    'scope' => array
  ]
);

// Copy index in between apps
\Algolia\AlgoliaSearch\AccountClient::copyIndex(
  SearchIndex indexSrc,
  SearchIndex indexDest
);

About this method # A

Make a copy of an index, including its records, settings, Synonyms, and Rules except for the enableReRanking setting.

With this method you can copy the entire index (records, settings, Synonyms, and Rules) or any subset of the following:

  • settings,
  • Synonyms,
  • and Rules.

Use the scope parameter to determine what you want to copy.

Copy operations overwrite destination indices. This means that everything besides the API keys and the Analytics data is lost.

Copying is an expensive operation:

  • When you have more than 100 pending requests, they’re automatically throttled.
  • When you have more than 5000 pending requests, further requests are ignored.

If needed, you can configure these limits.

During a copy operation, if your source index doesn’t exist, the operation is ignored. You can still perform a waitTask for this job.

API keys#

The API keys of the source are merged with the existing keys in the destination index.

Analytics#

Copying an index has no impact on Analytics, because you cannot copy an index’s analytics data.

Replicas#

Copying a source index that has replicas copies the index’s data, but not its replicas. The destination index doesn’t have replicas.

You can’t copy to a destination index that already has replicas.

Scopes#

Using the scope parameter, you can copy specific parts of your source index .

If you omit the scope parameter, then everything is copied. If you use it, you’re copying specific scopes rather than records.

For example, if you specify "settings" and "synonyms", you’re copying your source index’s settings and Synonyms, but ignoring its Rules and records. On the other hand, if you don’t specify a scope (that is, you omit the scope parameter) then the copy command works as by default: copying all records, settings, Synonyms, and Rules.

Copied items fully replace the corresponding scopes in the destination index. The engine doesn’t do any kind of merging of items that belong to the same scope, it fully overwrites them.

Whenever you use the scope parameter, the engine preserves items belonging to scopes that weren’t copied. For example, if you’re copying to an index that already has records, and you specify "settings" and "synonyms" as the scope, the engine will preserve the existing records in the destination index.

Examples # A

Copy an index#

1
2
// Copy indexNameSrc to indexNameDest
$res = $client->copyIndex('indexNameSrc', 'indexNameDest');

Copy resources between indices#

1
2
3
4
// Copy settings and synonyms (but not rules, nor records) from indexNameSrc to indexNameDest
$res = $client->copyIndex('indexNameSrc', 'indexNameDest', [
  'scope' => ['settings', 'synonyms']
]);

Copy index between apps#

1
2
3
4
5
6
$index1 = \Algolia\AlgoliaSearch\SearchClient::create('APP_ID_1', 'API_KEY_1')
            ->initIndex('index_name_1');
$index2 = \Algolia\AlgoliaSearch\SearchClient::create('APP_ID_2', 'API_KEY_2')
            ->initIndex('index_name_2');

\Algolia\AlgoliaSearch\AccountClient::copyIndex($index1, $index2);

Parameters # A

indexNameSrc #
type: string
Required

Name of the source index to copy.

indexNameDest #
type: string
Required

Name of the destination index.

indexSrc #
type: object
Required

Source index object.

indexDest #
type: object
Required

Destination index object.

scope #
type: list
Optional

An array containing any combination of the following strings:

  • settings
  • synonyms
  • rules

See more on how this parameter works.

Response # A

This section shows the JSON response returned by the API. Since each language encapsulates this response inside objects specific to that language and/or implementation, the actual type in your language might differ from what’s written here. You can view the response in the logs (using the getLogs method).

JSON format#

1
2
3
4
{
  "updatedAt": "2017-12-18T21:22:40.761Z",
  "taskID": 19541511530
}
updatedAt #
date string

Date at which the job to copy the index has been created.

taskID #
integer

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.

Did you find this page helpful?
PHP v3