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.
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Scala
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 done
await client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID });
$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']);
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 done
client.waitForTask("<SOURCE_INDEX_NAME>", response.getTaskID());
import (
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)
indexName := "<SOURCE_INDEX_NAME>"
appID := "<APPLICATION_ID>"
apiKey := "<API_KEY>"
searchClient, _ := search.NewClient(appID, apiKey)
operationIndexRequest := searchClient.NewApiOperationIndexRequest(
indexName,
search.NewOperationIndexParams(search.OPERATIONTYPE_COPY, "<DESTINATION_INDEX_NAME>"),
)
operationIndex, err := searchClient.OperationIndex(operationIndexRequest)
if err != nil {
panic(err)
}
taskResponse, err := searchClient.WaitForTask(
indexName,
operationIndex.TaskID,
nil,
nil,
nil,
)
if err != nil {
panic(err)
}
val response = client.operationIndex(
indexName = "<SOURCE_INDEX_NAME>",
operationIndexParams = OperationIndexParams(
operation = OperationType.Copy,
destination = "<DESTINATION_INDEX_NAME>"
),
)
// Poll the task status until it's done
client.waitTask("<SOURCE_INDEX_NAME>", response.taskID)
var response = await client.operationIndex(
indexName: '<SOURCE_INDEX_NAME>',
operationIndexParams: OperationIndexParams(
operation: OperationType.copy,
destination: '<DESTINATION_INDEX_NAME>'
),
);
// Poll the task status until it's done
await client.waitTask('<SOURCE_INDEX_NAME>', response.taskID);
// TBD
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.
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Scala
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 done
await client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID });
$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']);
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 done
client.waitForTask("<SOURCE_INDEX_NAME>", response.getTaskID());
val response = client.operationIndex(
indexName = "<SOURCE_INDEX_NAME>",
operationIndexParams = OperationIndexParams(
operation = OperationType.Move,
destination = "<DESTINATION_INDEX_NAME>"
),
)
// Poll the task status until it's done
client.waitTask("<SOURCE_INDEX_NAME>", response.taskID)
var response = await client.operationIndex(
indexName: '<SOURCE_INDEX_NAME>',
operationIndexParams: OperationIndexParams(
operation: OperationType.move,
destination: '<DESTINATION_INDEX_NAME>'
),
);
// Poll the task status until it's done
await client.waitTask('<SOURCE_INDEX_NAME>', response.taskID);
import (
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)
indexName := "<SOURCE_INDEX_NAME>"
appID := "<APPLICATION_ID>"
apiKey := "<API_KEY>"
searchClient, _ := search.NewClient(appID, apiKey)
operationIndexRequest := searchClient.NewApiOperationIndexRequest(
indexName,
search.NewOperationIndexParams(search.OPERATIONTYPE_MOVE, "<DESTINATION_INDEX_NAME>"),
)
operationIndex, err := searchClient.OperationIndex(operationIndexRequest)
if err != nil {
panic(err)
}
taskResponse, err := searchClient.WaitForTask(
indexName,
operationIndex.TaskID,
nil,
nil,
nil,
)
if err != nil {
panic(err)
}
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.
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Scala
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 done
await client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID });
$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']);
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 done
client.waitForTask("<SOURCE_INDEX_NAME>", response.getTaskID());
val response = client.operationIndex(
indexName = "<SOURCE_INDEX_NAME>",
operationIndexParams = OperationIndexParams(
operation = OperationType.Move,
destination = "<DESTINATION_INDEX_NAME>",
scope = listOf(ScopeType.Rules),
),
)
client.waitTask("<SOURCE_INDEX_NAME>", response.taskID)
var response = await client.operationIndex(
indexName: '<SOURCE_INDEX_NAME>',
operationIndexParams: OperationIndexParams(
operation: OperationType.move,
destination: '<DESTINATION_INDEX_NAME>',
scope: [ScopeType.rules],
),
);
await client.waitTask('<SOURCE_INDEX_NAME>', response.taskID);
import (
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)
indexName := "<SOURCE_INDEX_NAME>"
appID := "<APPLICATION_ID>"
apiKey := "<API_KEY>"
searchClient, _ := search.NewClient(appID, apiKey)
operationIndexRequest := searchClient.NewApiOperationIndexRequest(
indexName,
search.NewOperationIndexParams(
search.OPERATIONTYPE_MOVE,
"<DESTINATION_INDEX_NAME>",
search.WithOperationIndexParamsScope([]search.ScopeType{search.SCOPETYPE_RULES}),
),
)
operationIndex, err := searchClient.OperationIndex(operationIndexRequest)
if err != nil {
panic(err)
}
taskResponse, err := searchClient.WaitForTask(
indexName,
operationIndex.TaskID,
nil,
nil,
nil,
)
if err != nil {
panic(err)
}