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
- Ruby
- Scala
- Swift
using Algolia.Search.Clients;
using Algolia.Search.Http;
var client = new SearchClient(new SearchConfig("YOUR_APP_ID", "YOUR_API_KEY"));
var response = await client.OperationIndexAsync(
"<SOURCE_INDEX_NAME>",
new OperationIndexParams
{
Operation = Enum.Parse<OperationType>("Copy"),
Destination = "<DESTINATION_INDEX_NAME>",
}
);
await client.WaitForTaskAsync("<SOURCE_INDEX_NAME>", response.TaskID);
import 'package:algolia_client_search/algolia_client_search.dart';
final client = SearchClient(appId: 'YOUR_APP_ID', apiKey: 'YOUR_API_KEY');
final response = await client.operationIndex(
indexName: "<SOURCE_INDEX_NAME>",
operationIndexParams: OperationIndexParams(
operation: OperationType.fromJson("copy"),
destination: "<DESTINATION_INDEX_NAME>",
),
);
await client.waitTask('<SOURCE_INDEX_NAME>', response.taskID);
import "github.com/algolia/algoliasearch-client-go/v4/algolia/search"
client, err := search.NewClient("YOUR_APP_ID", "YOUR_API_KEY")
response, err := client.OperationIndex(client.NewApiOperationIndexRequest(
"<SOURCE_INDEX_NAME>",
search.NewEmptyOperationIndexParams().SetOperation(search.OperationType("copy")).SetDestination("<DESTINATION_INDEX_NAME>"),
))
if err != nil {
// handle the eventual error
panic(err)
}
// use the model directly
print(response)
taskResponse, err := searchClient.WaitForTask("<SOURCE_INDEX_NAME>", response.TaskID, nil, nil, nil)
if err != nil {
panic(err)
}
import com.algolia.api.SearchClient;
import com.algolia.model.search.*;
SearchClient client = new SearchClient("YOUR_APP_ID", "YOUR_API_KEY");
client.operationIndex(
"<SOURCE_INDEX_NAME>",
new OperationIndexParams().setOperation(OperationType.COPY).setDestination("<DESTINATION_INDEX_NAME>")
);
client.waitForTask("<SOURCE_INDEX_NAME>", response.getTaskID());
import { searchClient } from '@algolia/client-search';
const client = searchClient('YOUR_APP_ID', 'YOUR_API_KEY');
const response = await client.operationIndex({
indexName: '<SOURCE_INDEX_NAME>',
operationIndexParams: {
operation: 'copy',
destination: '<DESTINATION_INDEX_NAME>',
},
});
// use typed response
console.log(response);
await client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID: response.taskID });
import com.algolia.client.api.SearchClient
val client = SearchClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")
var response = client.operationIndex(
indexName = "<SOURCE_INDEX_NAME>",
operationIndexParams = OperationIndexParams(
operation = OperationType.entries.first { it.value == "copy" },
destination = "<DESTINATION_INDEX_NAME>",
),
)
// Use the response
println(response)
client.waitTask("<SOURCE_INDEX_NAME>", response.taskID)
use Algolia\AlgoliaSearch\Api\SearchClient;
$client = SearchClient::create('<YOUR_APP_ID>', '<YOUR_API_KEY>');
$response = $client->operationIndex(
'<SOURCE_INDEX_NAME>',
['operation' => 'copy',
'destination' => '<DESTINATION_INDEX_NAME>',
],
);
// play with the response
var_dump($response);
$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
from algoliasearch.search.client import SearchClient
_client = SearchClient("YOUR_APP_ID", "YOUR_API_KEY")
response = await _client.operation_index(
index_name="<SOURCE_INDEX_NAME>",
operation_index_params={
"operation": "copy",
"destination": "<DESTINATION_INDEX_NAME>",
},
)
# use the class directly
print(response)
# print the JSON response
print(response.to_json())
await client.wait_for_task(index_name="<SOURCE_INDEX_NAME>", task_id=response.task_id)
require 'algolia'
client = Algolia::SearchClient.create('YOUR_APP_ID', 'YOUR_API_KEY')
response = client.operation_index(
"<SOURCE_INDEX_NAME>",
OperationIndexParams.new(operation: 'copy', destination: "<DESTINATION_INDEX_NAME>")
)
# use the class directly
puts response
# print the JSON response
puts response.to_json
client.wait_for_task("<SOURCE_INDEX_NAME>", response.task_id)
import algoliasearch.api.SearchClient
val client = SearchClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")
val response = client.operationIndex(
indexName = "<SOURCE_INDEX_NAME>",
operationIndexParams = OperationIndexParams(
operation = OperationType.withName("copy"),
destination = "<DESTINATION_INDEX_NAME>"
)
)
// Use the response
val value = Await.result(response, Duration(100, "sec"))
client.waitTask("<SOURCE_INDEX_NAME>", response.getTaskID())
import Search
let client = try SearchClient(appID: "YOUR_APP_ID", apiKey: "YOUR_API_KEY")
let response = try await client.operationIndex(
indexName: "<SOURCE_INDEX_NAME>",
operationIndexParams: OperationIndexParams(
operation: OperationType.copy,
destination: "<DESTINATION_INDEX_NAME>"
)
)
try await client.waitForTask(with: response.taskID, in: "<SOURCE_INDEX_NAME>")
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
- Ruby
- Scala
- Swift
var response = await client.OperationIndexAsync(
"<SOURCE_INDEX_NAME>",
new OperationIndexParams
{
Operation = Enum.Parse<OperationType>("Move"),
Destination = "<DESTINATION_INDEX_NAME>",
}
);
await client.WaitForTaskAsync("<SOURCE_INDEX_NAME>", response.TaskID);
final response = await client.operationIndex(
indexName: "<SOURCE_INDEX_NAME>",
operationIndexParams: OperationIndexParams(
operation: OperationType.fromJson("move"),
destination: "<DESTINATION_INDEX_NAME>",
),
);
await client.waitTask('<SOURCE_INDEX_NAME>', response.taskID);
response, err := client.OperationIndex(client.NewApiOperationIndexRequest(
"<SOURCE_INDEX_NAME>",
search.NewEmptyOperationIndexParams().SetOperation(search.OperationType("move")).SetDestination("<DESTINATION_INDEX_NAME>"),
))
if err != nil {
// handle the eventual error
panic(err)
}
// use the model directly
print(response)
taskResponse, err := searchClient.WaitForTask("<SOURCE_INDEX_NAME>", response.TaskID, nil, nil, nil)
if err != nil {
panic(err)
}
client.operationIndex(
"<SOURCE_INDEX_NAME>",
new OperationIndexParams().setOperation(OperationType.MOVE).setDestination("<DESTINATION_INDEX_NAME>")
);
client.waitForTask("<SOURCE_INDEX_NAME>", response.getTaskID());
const response = await client.operationIndex({
indexName: '<SOURCE_INDEX_NAME>',
operationIndexParams: {
operation: 'move',
destination: '<DESTINATION_INDEX_NAME>',
},
});
// use typed response
console.log(response);
await client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID: response.taskID });
var response = client.operationIndex(
indexName = "<SOURCE_INDEX_NAME>",
operationIndexParams = OperationIndexParams(
operation = OperationType.entries.first { it.value == "move" },
destination = "<DESTINATION_INDEX_NAME>",
),
)
// Use the response
println(response)
client.waitTask("<SOURCE_INDEX_NAME>", response.taskID)
$response = $client->operationIndex(
'<SOURCE_INDEX_NAME>',
['operation' => 'move',
'destination' => '<DESTINATION_INDEX_NAME>',
],
);
// play with the response
var_dump($response);
$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
response = await _client.operation_index(
index_name="<SOURCE_INDEX_NAME>",
operation_index_params={
"operation": "move",
"destination": "<DESTINATION_INDEX_NAME>",
},
)
# use the class directly
print(response)
# print the JSON response
print(response.to_json())
await client.wait_for_task(index_name="<SOURCE_INDEX_NAME>", task_id=response.task_id)
response = client.operation_index(
"<SOURCE_INDEX_NAME>",
OperationIndexParams.new(operation: 'move', destination: "<DESTINATION_INDEX_NAME>")
)
# use the class directly
puts response
# print the JSON response
puts response.to_json
client.wait_for_task("<SOURCE_INDEX_NAME>", response.task_id)
val response = client.operationIndex(
indexName = "<SOURCE_INDEX_NAME>",
operationIndexParams = OperationIndexParams(
operation = OperationType.withName("move"),
destination = "<DESTINATION_INDEX_NAME>"
)
)
// Use the response
val value = Await.result(response, Duration(100, "sec"))
client.waitTask("<SOURCE_INDEX_NAME>", response.getTaskID())
let response = try await client.operationIndex(
indexName: "<SOURCE_INDEX_NAME>",
operationIndexParams: OperationIndexParams(
operation: OperationType.move,
destination: "<DESTINATION_INDEX_NAME>"
)
)
try await client.waitForTask(with: response.taskID, in: "<SOURCE_INDEX_NAME>")
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
- Ruby
- Scala
- Swift
var response = await client.OperationIndexAsync(
"<SOURCE_INDEX_NAME>",
new OperationIndexParams
{
Operation = Enum.Parse<OperationType>("Move"),
Destination = "<DESTINATION_INDEX_NAME>",
Scope = new List<ScopeType>
{
Enum.Parse<ScopeType>("Rules"),
Enum.Parse<ScopeType>("Settings")
},
}
);
await client.WaitForTaskAsync("<SOURCE_INDEX_NAME>", response.TaskID);
final response = await client.operationIndex(
indexName: "<SOURCE_INDEX_NAME>",
operationIndexParams: OperationIndexParams(
operation: OperationType.fromJson("move"),
destination: "<DESTINATION_INDEX_NAME>",
scope: [
ScopeType.fromJson("rules"),
ScopeType.fromJson("settings"),
],
),
);
await client.waitTask('<SOURCE_INDEX_NAME>', response.taskID);
response, err := client.OperationIndex(client.NewApiOperationIndexRequest(
"<SOURCE_INDEX_NAME>",
search.NewEmptyOperationIndexParams().SetOperation(search.OperationType("move")).SetDestination("<DESTINATION_INDEX_NAME>").SetScope(
[]search.ScopeType{search.ScopeType("rules"), search.ScopeType("settings")}),
))
if err != nil {
// handle the eventual error
panic(err)
}
// use the model directly
print(response)
taskResponse, err := searchClient.WaitForTask("<SOURCE_INDEX_NAME>", response.TaskID, nil, nil, nil)
if err != nil {
panic(err)
}
client.operationIndex(
"<SOURCE_INDEX_NAME>",
new OperationIndexParams()
.setOperation(OperationType.MOVE)
.setDestination("<DESTINATION_INDEX_NAME>")
.setScope(List.of(ScopeType.RULES, ScopeType.SETTINGS))
);
client.waitForTask("<SOURCE_INDEX_NAME>", response.getTaskID());
const response = await client.operationIndex({
indexName: '<SOURCE_INDEX_NAME>',
operationIndexParams: {
operation: 'move',
destination: '<DESTINATION_INDEX_NAME>',
scope: ['rules', 'settings'],
},
});
// use typed response
console.log(response);
await client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID: response.taskID });
var response = client.operationIndex(
indexName = "<SOURCE_INDEX_NAME>",
operationIndexParams = OperationIndexParams(
operation = OperationType.entries.first { it.value == "move" },
destination = "<DESTINATION_INDEX_NAME>",
scope = listOf(ScopeType.entries.first { it.value == "rules" }, ScopeType.entries.first { it.value == "settings" }),
),
)
// Use the response
println(response)
client.waitTask("<SOURCE_INDEX_NAME>", response.taskID)
$response = $client->operationIndex(
'<SOURCE_INDEX_NAME>',
['operation' => 'move',
'destination' => '<DESTINATION_INDEX_NAME>',
'scope' => [
'rules',
'settings',
],
],
);
// play with the response
var_dump($response);
$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
response = await _client.operation_index(
index_name="<SOURCE_INDEX_NAME>",
operation_index_params={
"operation": "move",
"destination": "<DESTINATION_INDEX_NAME>",
"scope": [
"rules",
"settings",
],
},
)
# use the class directly
print(response)
# print the JSON response
print(response.to_json())
await client.wait_for_task(index_name="<SOURCE_INDEX_NAME>", task_id=response.task_id)
response = client.operation_index(
"<SOURCE_INDEX_NAME>",
OperationIndexParams.new(
operation: 'move',
destination: "<DESTINATION_INDEX_NAME>",
scope: ['rules', 'settings']
)
)
# use the class directly
puts response
# print the JSON response
puts response.to_json
client.wait_for_task("<SOURCE_INDEX_NAME>", response.task_id)
val response = client.operationIndex(
indexName = "<SOURCE_INDEX_NAME>",
operationIndexParams = OperationIndexParams(
operation = OperationType.withName("move"),
destination = "<DESTINATION_INDEX_NAME>",
scope = Some(Seq(ScopeType.withName("rules"), ScopeType.withName("settings")))
)
)
// Use the response
val value = Await.result(response, Duration(100, "sec"))
client.waitTask("<SOURCE_INDEX_NAME>", response.getTaskID())
let response = try await client.operationIndex(
indexName: "<SOURCE_INDEX_NAME>",
operationIndexParams: OperationIndexParams(
operation: OperationType.move,
destination: "<DESTINATION_INDEX_NAME>",
scope: [ScopeType.rules, ScopeType.settings]
)
)
try await client.waitForTask(with: response.taskID, in: "<SOURCE_INDEX_NAME>")