Copy Index
addObject
ACL
$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
We released a new version of the PHP API client in public beta. Read the beta documentation for more information.
We released a new version of the JavaScript API client in public beta. Read the beta documentation for more information.
We released a new version of the Java API client in public beta. Read the beta documentation for more information.
You’re currently reading the JavaScript API client v4 documentation. Check the migration guide to learn how to upgrade from v3 to v4. You can still access the v3 documentation.
You’re currently reading the Ruby API client v2 documentation. Check the migration guide to learn how to upgrade from v1 to v2. You can still access the v1 documentation.
Copy an index, including its records, Synonyms, Rules, and settings (except for enableReRanking
).
You can copy the entire index (records, settings, Synonyms, and Rules) or one or more of the following scopes:
- Settings
- Synonyms
- Rules
Copy operations overwrite destination indices. Everything besides the API keys and the Analytics data is replaced.
Copying an index is expensive and is rate-limited:
- If you have more than 100 pending requests, the engine throttles your requests.
- If you have more than 5,000 pending requests, further requests are ignored.
If your source index doesn’t exist, the copy operation is ignored.
You can still use 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. You can’t 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, everything is copied.
For example, if you set the scope to "settings"
and "synonyms"
, you’re copying your source index’s settings and Synonyms, but not its Rules and records.
Copied items replace the corresponding scopes in the destination index. The engine doesn’t merge different items belonging to the same scope.
When copying an index with the scope
parameter, the engine preserves items in different scopes. For example, if you select "settings"
and "synonyms"
as the scope, and the destination index already has records, the engine preserves the existing records in the destination index.
Examples
Read the Algolia CLI documentation for more information.
To see a complete app, including all import and setup instructions, go to Install the .NET API client.
To see a complete app, including all import and setup instructions, go to Install the Go API client.
To see a complete app, including all import and setup instructions, go to Install the Java API client.
To see a complete app, including all import and setup instructions, go to Install the Kotlin API client.
To see a complete app, including all import and setup instructions, go to Install the Scala API client.
To see a complete app, including all import and setup instructions, go to Install the Swift API client.
Copy an index
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');
Copy parts of an index with scopes
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']
]);
Copy index between apps
1
2
3
4
5
6
7
8
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');
AccountClient::copyIndex($sourceIndex, $targetIndex);
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
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. |