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 );
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.
About this method
Copy an index, including its records, synonyms, rules, and settings.
You can copy the entire index (records, settings, Synonyms, and Rules) or one or more of the following scopes:
- Settings
- Synonyms
- Rules
This method does not copy the enableReRanking
and mode
settings.
Rate limiting
Copying an index is rate-limited:
- If you have more than 100 pending requests, your requests are throttled.
- If you have more than 5,000 pending requests, further requests are ignored.
Source indices
Copying a source index that doesn’t exist creates a new index with 0 records.
Destination indices
Within the same Algolia application: destination indices are overwritten. Everything besides the API keys and Analytics data is replaced.
Between applications (API clients): copying an index fails if the destination index exists.
Between applications (CLI):
objects (records, synonyms, rules) with the same objectID
, and existing settings,
are replaced in the destination index.
Objects with different objectID
are added to the index.
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
To copy parts of your source index, use the scope
parameter.
If you omit the scope
parameter, everything is copied.
For example, to copy an index’s settings and synonyms, but not records and rules,
set the scope
parameter to: ["settings", "synonyms"]
.
-
The scope is replaced completely. Different items belonging to the same scope are not merged. For example, with
scope: "settings"
, all settings of the destination index are replaced with the settings of the source index. - Items in different scopes are preserved.
- If you set the
scope
parameter, records aren’t copied.
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
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);
Parameters
Parameter | Description |
---|---|
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.
Each API client encapsulates this response inside objects specific to the programming language,
so that the actual response might be different.
You can view the response by using the getLogs
method.
Don’t rely on the order of attributes in the response, as JSON doesn’t guarantee the ordering of keys in objects.
JSON format
1
2
3
4
{
"updatedAt": "2017-12-18T21:22:40.761Z",
"taskID": 19541511530
}
Field | Description |
---|---|
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. |