Copy Index | JavaScript API Client V3 (Deprecated)
addObject
ACL
client.copyIndex( string indexNameSrc, string indexNameDest, callback ) client.copyIndex( string indexNameSrc, string indexNameDest, array scope, callback )
About this method
Make a copy of an index, including its objects, settings, synonyms, and query rules.
This method enables you to copy the entire index (objects, settings, synonyms, and rules) OR one or more of the following index elements:
- settings
- synonyms
- and rules (query rules)
You can control which of these are copied by using the scope parameter.
The copy command will overwrite the destination index. This means everything will be lost in the destination index except its API keys and Analytics data.
Regarding the API Keys, the source’s API Keys will be merged with the existing keys of the destination index.
Note this is an expensive operation:
- when you have more than 100 requests pending, your requests will be throttled.
- when you have more than 5000 requests pending, further requests will be ignored.
- if needed, these values can be tuned through configuration.
Copying an index will have no impact on analytics data because you cannot copy an index’s analytics data.
Regarding replicas:
- Copying an index having replicas is possible, but the replicas will not be copied, only the data. The destination index will not have replicas.
- Copying to a existing index having replicas is not possible.
Before performing this 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 wait for it to finish in your code, the wait will never resolve.
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 in between app
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
The “scope” parameter is an array of strings that refer to the following items:
If you omit the scope parameter, then all objects and all scope items are copied. But if you use the scope parameter, you will no longer be copying records (objects); instead, you will be copying specified scopes. For example, if you specify {“settings”, “synonyms”}, then only those 2 items will be copied - not the “rules” and not the objects. On the other hand, if you do not specify a scope - that is, you omit the scope parameter - then the copy command will work as by default: copying all objects, settings, synonyms, and rules. Note: using scope has the following 2 consequences:
|
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. |