The generated API clients are a work in progress, you can also find our stable clients on the Algolia documentation.

Skip to main content

Copy or move an index, rules, settings or synonyms

caution

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.

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 });

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.

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 });

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.

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 });