You can copy (duplicate) or move (rename) indices, including their associated records, settings, synonyms, and rules, using the Algolia dashboard or the API.
You can’t move an index between different Algolia applications
but you can create a copy and delete the original index.
For more information,
see Copy indices between apps.
import"github.com/algolia/algoliasearch-client-go/v4/algolia/search"client,err:=search.NewClient("ALGOLIA_APPLICATION_ID","ALGOLIA_API_KEY")iferr!=nil{// The client can fail to initialize if you pass an invalid parameter.panic(err)}response,err:=client.OperationIndex(client.NewApiOperationIndexRequest("<SOURCE_INDEX_NAME>",search.NewEmptyOperationIndexParams().SetOperation(search.OperationType("move")).SetDestination("<DESTINATION_INDEX_NAME>")))iferr!=nil{// handle the eventual errorpanic(err)}
fromalgoliasearch.search.clientimportSearchClientSyncfromjsonimportloads# In an asynchronous context, you can use SearchClient instead, which exposes the exact same methods.
client=SearchClientSync("ALGOLIA_APPLICATION_ID","ALGOLIA_API_KEY")response=client.operation_index(index_name="<SOURCE_INDEX_NAME>",operation_index_params={"operation":"move","destination":"<DESTINATION_INDEX_NAME>",},)
If an index with the new name already exists, moving overwrites it.
To avoid overwriting existing indices,
check if an index exists with the indexExists helper.
If the source index doesn’t exist, Algolia ignores the move operation.
Renaming an index doesn’t change the associated analytics:
Analytics associated with the original index keep their name.
A new set of analytics is started with the new name.
You can move an index to a destination index with replicas.
First, the source index data replaces the destination index data.
Then, the data is copied to the replicas.
Indices used as a Recommend data source
If an index is the data source for Recommend models, you can’t rename it directly.
If you do, you’ll lose the relationship between the recommended records and their source.
import"github.com/algolia/algoliasearch-client-go/v4/algolia/search"client,err:=search.NewClient("ALGOLIA_APPLICATION_ID","ALGOLIA_API_KEY")iferr!=nil{// The client can fail to initialize if you pass an invalid parameter.panic(err)}response,err:=client.OperationIndex(client.NewApiOperationIndexRequest("<SOURCE_INDEX_NAME>",search.NewEmptyOperationIndexParams().SetOperation(search.OperationType("copy")).SetDestination("<DESTINATION_INDEX_NAME>")))iferr!=nil{// handle the eventual errorpanic(err)}
fromalgoliasearch.search.clientimportSearchClientSyncfromjsonimportloads# In an asynchronous context, you can use SearchClient instead, which exposes the exact same methods.
client=SearchClientSync("ALGOLIA_APPLICATION_ID","ALGOLIA_API_KEY")response=client.operation_index(index_name="<SOURCE_INDEX_NAME>",operation_index_params={"operation":"copy","destination":"<DESTINATION_INDEX_NAME>",},)
If the source index doesn’t exist, an empty index is created.
If an index with this name already exists, it will be overwritten.
To prevent overwriting existing indices,
check if an index exists with the indexExists helper.
Copy indices partially
To copy parts of an index, use the scope parameter of the operationIndex method.
For example, to copy only the synonyms and settings between indices, but not records or rules:
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")})))iferr!=nil{// handle the eventual errorpanic(err)}
If you use the scope parameter, records aren’t copied to the new index.
Existing items of the scope are replaced.
Items belonging to other scopes are preserved.
For example, if you use the settings scope, only the settings are copied to the destination index, keeping the records, synonyms, and rules.
Indices with replicas
Copying a source index that has replicas copies the index’s data, but not its replicas.
The destination index won’t have replicas.
You can’t copy to a destination index with replicas.
Copy indices between different applications
To copy an index between different Algolia applications,
use the Algolia CLI.