Copy Index | Ruby API Client V1 (Deprecated)
This version of the Ruby API client has been deprecated in favor of the latest version of the Ruby API client.
addObject
ACL
client.copy_index( String indexNameSrc, String indexNameDest ) client.copy_index( String indexNameSrc, String indexNameDest, Array scope ) # Copy index in between apps Algolia::AccountClient.copy_index( Index indexSrc, Index indexDest )
About this method
Make a copy of an index, including its records, settings, Synonyms, and Rules.
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.
Before performing a copy operation, make sure your source index exists. Our API creates a job even when an index doesn’t exist, but because it has no source index, the job won’t be able to end. If you perform a waitTask
for this job, the wait will never resolve.
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
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 the current index to "indexNameDest".
$index->copyTo('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
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:
See more on how this parameter works. |
Response
In this section we document the JSON response returned by the API. Each language will encapsulate this response inside objects specific to the language and/or the implementation. So the actual type in your language might differ from what is documented.
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. |