Copy or move an index, rules, settings or synonyms
This method is made to be used within the same Algolia application, for cross application operations, read our dedicated guide.
Copy an index
When you copy an index, it doesn’t copy the associated analytics data. The new index starts fresh. Be careful when using the operationIndex
method with the copy
parameter to overwrite an existing index, as it associates the existing analytics data of the overwritten index with the new one.
- JavaScript
- PHP
- Java
js
import { algoliasearch } from 'algoliasearch';const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');const { taskID } = await client.operationIndex({indexName: '<SOURCE_INDEX_NAME>',operationIndexParams: {operation: 'copy',destination: '<DESTINATION_INDEX_NAME>',},});// Poll the task status until it's doneawait client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID });
js
import { algoliasearch } from 'algoliasearch';const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');const { taskID } = await client.operationIndex({indexName: '<SOURCE_INDEX_NAME>',operationIndexParams: {operation: 'copy',destination: '<DESTINATION_INDEX_NAME>',},});// Poll the task status until it's doneawait client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID });
php
$client = SearchClient::create('<YOUR_APP_ID>','<YOUR_API_KEY>');$response = $client->operationIndex('<SOURCE_INDEX_NAME>',['operation' => 'copy','destination' => '<DESTINATION_INDEX_NAME>',]);// Poll the task status with defaults values$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
php
$client = SearchClient::create('<YOUR_APP_ID>','<YOUR_API_KEY>');$response = $client->operationIndex('<SOURCE_INDEX_NAME>',['operation' => 'copy','destination' => '<DESTINATION_INDEX_NAME>',]);// Poll the task status with defaults values$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
java
import com.algolia.model.search.*;UpdatedAtResponse response = client.operationIndex("<SOURCE_INDEX_NAME>",new OperationIndexParams().setOperation(OperationType.COPY).setDestination("<DESTINATION_INDEX_NAME>"));// Poll the task status until it's doneclient.waitForTask("<SOURCE_INDEX_NAME>", response.getTaskID());
java
import com.algolia.model.search.*;UpdatedAtResponse response = client.operationIndex("<SOURCE_INDEX_NAME>",new OperationIndexParams().setOperation(OperationType.COPY).setDestination("<DESTINATION_INDEX_NAME>"));// Poll the task status until it's doneclient.waitForTask("<SOURCE_INDEX_NAME>", response.getTaskID());
Rename/move an index
Changing the name of an index doesn’t change the name of the index’s analytics. The new name references new analytics; the old and new analytics aren’t merged. If you want to preserve an index’s analytics history, you need to keep using the old name.
- JavaScript
- PHP
- Java
js
import { algoliasearch } from 'algoliasearch';const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');const { taskID } = await client.operationIndex({indexName: '<SOURCE_INDEX_NAME>',operationIndexParams: {operation: 'move',destination: '<DESTINATION_INDEX_NAME>',},});// Poll the task status until it's doneawait client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID });
js
import { algoliasearch } from 'algoliasearch';const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');const { taskID } = await client.operationIndex({indexName: '<SOURCE_INDEX_NAME>',operationIndexParams: {operation: 'move',destination: '<DESTINATION_INDEX_NAME>',},});// Poll the task status until it's doneawait client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID });
php
$client = SearchClient::create('<YOUR_APP_ID>','<YOUR_APP_ID>');$response = $client->operationIndex('<SOURCE_INDEX_NAME>',['operation' => 'move','destination' => '<DESTINATION_INDEX_NAME>',]);// Poll the task status with defaults values$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
php
$client = SearchClient::create('<YOUR_APP_ID>','<YOUR_APP_ID>');$response = $client->operationIndex('<SOURCE_INDEX_NAME>',['operation' => 'move','destination' => '<DESTINATION_INDEX_NAME>',]);// Poll the task status with defaults values$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
java
import com.algolia.model.search.*;UpdatedAtResponse response = client.operationIndex("<SOURCE_INDEX_NAME>",new OperationIndexParams().setOperation(OperationType.MOVE).setDestination("<DESTINATION_INDEX_NAME>"));// Poll the task status until it's doneclient.waitForTask("<SOURCE_INDEX_NAME>", response.getTaskID());
java
import com.algolia.model.search.*;UpdatedAtResponse response = client.operationIndex("<SOURCE_INDEX_NAME>",new OperationIndexParams().setOperation(OperationType.MOVE).setDestination("<DESTINATION_INDEX_NAME>"));// Poll the task status until it's doneclient.waitForTask("<SOURCE_INDEX_NAME>", response.getTaskID());
Scope your operation
When the scope is absent from the request, the index will be fully copied, but you can also decide to specify the scope of what you'd like to copy.
The available scopes are: rules
, settings
, synonyms
. You can provide one or many.
- JavaScript
- PHP
- Java
js
import { algoliasearch } from 'algoliasearch';const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');const { taskID } = await client.operationIndex({indexName: '<SOURCE_INDEX_NAME>',operationIndexParams: {operation: 'move',destination: '<DESTINATION_INDEX_NAME>',scope: ['rules'],},});// Poll the task status until it's doneawait client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID });
js
import { algoliasearch } from 'algoliasearch';const client = algoliasearch('<YOUR_APP_ID>', '<YOUR_API_KEY>');const { taskID } = await client.operationIndex({indexName: '<SOURCE_INDEX_NAME>',operationIndexParams: {operation: 'move',destination: '<DESTINATION_INDEX_NAME>',scope: ['rules'],},});// Poll the task status until it's doneawait client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID });
php
$client = SearchClient::create('<YOUR_APP_ID>','<YOUR_APP_ID>');$response = $client->operationIndex('<SOURCE_INDEX_NAME>',['operation' => 'move','destination' => '<DESTINATION_INDEX_NAME>','scope' => ['rules'],]);// Poll the task status with defaults values$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
php
$client = SearchClient::create('<YOUR_APP_ID>','<YOUR_APP_ID>');$response = $client->operationIndex('<SOURCE_INDEX_NAME>',['operation' => 'move','destination' => '<DESTINATION_INDEX_NAME>','scope' => ['rules'],]);// Poll the task status with defaults values$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
java
import com.algolia.model.search.*;UpdatedAtResponse response = client.operationIndex("<SOURCE_INDEX_NAME>",new OperationIndexParams().setOperation(OperationType.MOVE).setDestination("<DESTINATION_INDEX_NAME>").addScope(ScopeType.RULES));// Poll the task status until it's doneclient.waitForTask("<SOURCE_INDEX_NAME>", response.getTaskID());
java
import com.algolia.model.search.*;UpdatedAtResponse response = client.operationIndex("<SOURCE_INDEX_NAME>",new OperationIndexParams().setOperation(OperationType.MOVE).setDestination("<DESTINATION_INDEX_NAME>").addScope(ScopeType.RULES));// Poll the task status until it's doneclient.waitForTask("<SOURCE_INDEX_NAME>", response.getTaskID());