> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Copy index

> Copy an index, including its records, synonyms, rules, and settings.

export const Legacy = ({title, href}) => {
  return <Note>

    This page documents an earlier version of the API client.
    For the latest version, see <a href={href}>{title}</a>.

    </Note>;
};

<Legacy title="Copy or move an index" href="/doc/libraries/sdk/methods/search/operation-index" />

**Required ACL:** `addObject`

You can **copy the entire index** (records, settings, synonyms, and rules) or one or more of the following [scopes](#scopes):

* Settings
* Synonyms
* Rules

This method **doesn't copy** the [`enableReRanking`](/doc/api-reference/api-parameters/enableReRanking) and [`mode`](/doc/api-reference/api-parameters/mode) settings.

### Rate limiting

Copying an index is [rate-limited](https://support.algolia.com/hc/en-us/articles/4406975251089#when-do-we-trigger-the-rate-limit):

* If you have more than 100 pending requests, your requests are throttled.
* If you have more than 5,000 pending requests, further requests are ignored.

### Source indices

Copying a source index that doesn't exist creates a new index with 0 records.
If the source index has replicas, the replicas won't be copied.

### Destination indices

When copying indices within the same Algolia application,
the destination index is replaced if it exists.

You can't copy an index between two Algolia applications,
if the destination index exists.

Everything apart from the analytics data is replaced.
You can't copy to a destination index that already has replicas.

### Analytics

Copying an index has no impact on Analytics.
[You can't copy an index's analytics data](/doc/guides/sending-and-managing-data/manage-indices-and-apps/manage-indices/concepts/indices-analytics).

### Scopes

To copy parts of your source index, use the [`scope`](#param-scope) parameter.
If you omit the `scope` parameter, **everything is copied**.

For example, to copy an index's settings and synonyms, but not records and rules,
set the `scope` parameter to: `["settings", "synonyms"]`.

* The scope is replaced completely.
  Different items belonging to the same scope aren't merged.
  For example, with `scope: "settings"`,
  all settings of the destination index are replaced with the settings of the source index.

* Items in different scopes are preserved.

* If you set the `scope` parameter, records aren't copied.

## Examples

### Copy an index

<CodeGroup>
  ```cs C# theme={"system"}
  // Use an API key with `addObject` ACL
  var client = new SearchClient("YourApplicationID", "YourAPIKey");

  // Copy `indexNameSrc` to `indexNameDest`
  client.CopyIndex("indexNameSrc", "indexNameDest");

  // Asynchronous
  await client.CopyIndexAsync("indexNameSrc", "indexNameDest");
  ```

  ```go Go theme={"system"}
  // Use an API key with `addObject` ACL
  client := search.NewClient("YourApplicationID", "YourAPIKey")

  // Copy `indexNameSrc` to `indexNameDest`
  res, err := client.CopyIndex("indexNameSrc", "indexNameDest")
  ```

  ```java Java theme={"system"}
  // Use an API key with `addObject` ACL
  SearchClient client = DefaultSearchClient.create("YourApplicationID", "YourAPIKey");

  // Copy `indexNameSrc` to `indexNameDest`
  client.copyIndex("indexNameSrc", "indexNameDest");

  // Asynchronous
  client.copyIndexAsync("indexNameSrc", "indexNameDest");
  ```

  ```js JavaScript theme={"system"}
  const algoliasearch = require('algoliasearch');

  // Use an API key with `addObject` ACL
  const client = algoliasearch('YourApplicationID', 'YourAPIKey');

  // Copy `indexNameSrc` to `indexNameDest`
  client.copyIndex('indexNameSrc', 'indexNameDest');
  ```

  ```kotlin Kotlin theme={"system"}
  // Use an API key with `addObject` ACL
  val client = ClientSearch(
    ApplicationID("YourApplicationID")
    APIKey("YourAPIKey")
  )
  // Copy `indexNameSrc` to `indexNameDest`
  val index = client.initIndex(IndexName("indexNameSrc"))
  index.copyIndex(IndexName("indexNameDest"))
  ```

  ```php PHP theme={"system"}
  <?php
  require_once __DIR__."/vendor/autoload.php";
  use Algolia\AlgoliaSearch\SearchClient;

  // Use an API key with `addObject` ACL
  $client = SearchClient::create(
    'YourApplicationID', 'YourAPIKey'
  );

  // Copy `indexNameSrc` to `indexNameDest`
  $client->copyIndex('indexNameSrc', 'indexNameDest');
  ```

  ```python Python theme={"system"}
  from algoliasearch.search_client import SearchClient

  # Use an API key with `addObject` ACL
  client = SearchClient.create("YourApplicationID", "YourAPIKey")

  # Copy `indexNameSrc` to `indexNameDest`
  client.copy_index("indexNameSrc", "indexNameDest")
  ```

  ```ruby Ruby theme={"system"}
  require 'algolia'

  # Use an API key with `addObject` ACL
  client = Algolia::Search::Client.create(
    'YourApplicationID', 'YourAPIKey'
  )

  # Copy `indexNameSrc` to `indexNameDest`
  client.copy_index('indexNameSrc', 'indexNameDest')
  ```

  ```scala Scala theme={"system"}
  // Use an API key with `addObject` ACL
  val client = new AlgoliaClient("YourApplicationID", "YourAPIKey")

  // Copy `indexNameSrc` to `indexNameDest`
  client.execute { copy index "indexNameSrc" to "indexNameDest" }
  ```

  ```swift Swift theme={"system"}
  import AlgoliaSearchClient

  // Use an API key with `addObject` ACL
  let client = SearchClient(
    appID: "YourApplicationID",
    apiKey: "YourAPIKey"
  )

  // Copy `indexNameSrc` to `indexNameDest`
  client.copyIndex(from: "indexNameSrc", to: "indexNameDest") { result in
    if case .success(let response) = result {
      print("Response: \(response)")
    }
  }
  ```
</CodeGroup>

### Copy parts of an index with scopes

<CodeGroup>
  ```cs C# theme={"system"}
  // Use an API key with `addObject` ACL
  var client = new SearchClient("YourApplicationID", "YourAPIKey");

  // Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`
  List<string> scopes = new List<string>() {
      CopyScope.Settings,
      CopyScope.Synonyms
  };

  client.CopyIndex("indexNameSrc","indexNameDest",scope: scopes);

  // Asynchronous
  client.CopyIndexAsync("indexNameSrc","indexNameDest",scope: scopes);
  ```

  ```go Go theme={"system"}
  // Use an API key with `addObject` ACL
  client := search.NewClient("YourApplicationID", "YourAPIKey")

  // Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`
  res, err := client.CopyIndex(
    "indexNameSrc",
    "indexNameDest",
    opt.Scopes("settings", "synonyms"),
  )
  ```

  ```java Java theme={"system"}
  // Use an API key with `addObject` ACL
  SearchClient client = DefaultSearchClient.create("YourApplicationID", "YourAPIKey");

  // Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`
  client.copyIndex(
    "indexNameSrc", "indexNameDest",
    Arrays.asList("settings", "synonyms")
  );
  ```

  ```js JavaScript theme={"system"}
  // Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`
  client.copyIndex('indexNameSrc', 'indexNameDest', {
    scope: ['settings', 'synonyms']
  });
  ```

  ````kotlin Kotlin theme={"system"}
  // Use an API key with `addObject` ACL
  val client = ClientSearch(
    ApplicationID("YourApplicationID"),
    APIKey("YourAPIKey")
  )

  // Copy only synonyms and settings from `indexNameSrc` to `indexNameDest`
  val index = client.initIndex(IndexName("indexNameSrc"))
  val scopes = listOf(
      Scope.Settings,
      Scope.Synonyms
  )
  index.copyIndex(IndexName("indexNameDest"), scopes)

  ```php PHP
  <?php
  require_once __DIR__."/vendor/autoload.php";
  use Algolia\AlgoliaSearch\SearchClient;

  // Use an API key with `addObject` ACL
  $client = SearchClient::create(
    'YourApplicationID', 'YourAPIKey'
  );

  // Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`
  $client->copyIndex('indexNameSrc', 'indexNameDest', [
    'scope' => ['settings', 'synonyms']
  ]);
  ````

  ```python Python theme={"system"}
  from algoliasearch.search_client import SearchClient

  # Use an API key with `addObject` ACL
  client = SearchClient.create("YourApplicationID", "YourAPIKey")

  # Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`
  client.copy_index("indexNameSrc", "indexNameDest", {
      "scope": ["settings", "synonyms"]
  })
  ```

  ```ruby Ruby theme={"system"}
  require 'algolia'

  # Use an API key with `addObject` ACL
  client = Algolia::Search::Client.create(
    'YourApplicationID', 'YourAPIKey'
  )

  # Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`
  client.copy_index('indexNameSrc', 'indexNameDest', {
    scope: ['settings', 'synonyms']
  })
  ```

  ```scala Scala theme={"system"}
  // Use an API key with `addObject` ACL
  val client = new AlgoliaClient("YourApplicationID", "YourAPIKey")

  // Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`
  client.execute {
    copy index "indexNameSrc" to "indexNameDest" scopes Seq("settings", "synonyms")
  }
  ```

  ```swift Swift theme={"system"}
  import AlgoliaSearchClient

  // Use an API key with `addObject` ACL
  let client = SearchClient(
    appID: "YourApplicationID",
    apiKey: "YourAPIKey"
  )

  // Copy only settings and synonyms from `indexNameSrc` to `indexNameDest`
  client.copyIndex(
    from: "indexNameSrc",
    to: "indexNameDest",
    scope: [Scope.settings, Scope.synonyms]
  )
  ```
</CodeGroup>

### Copy index between apps

<CodeGroup>
  ```cs C# theme={"system"}
  // Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`
  SearchClient sourceClient = new SearchClient("SOURCE_APP_ID", "SOURCE_API_KEY");
  SearchClient targetClient = new SearchClient("TARGET_APP_ID", "TARGET_API_KEY");

  SearchIndex sourceIndex = sourceClient.InitIndex("indexNameSrc");
  SearchIndex targetIndex = targetClient.InitIndex("indexNameDest");

  AccountClient accountClient = new AccountClient();

  // Provide your 'Record' class for serializing the records during copying
  // This method throws an exception if `targetIndex` exists
  accountClient.CopyIndex<Record>(sourceIndex, targetIndex);

  // Asynchronous
  await accountClient.CopyIndexAsync<Record>(sourceIndex, targetIndex);
  ```

  ```go Go theme={"system"}
  // Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`
  sourceIndex = search.NewClient("SOURCE_APP_ID", "SOURCE_API_KEY").InitIndex("indexNameSrc")
  targetIndex = search.NewClient("TARGET_APP_ID", "TARGET_API_KEY").InitIndex("indexNameDest")

  res, err := search.NewAccount().CopyIndex(sourceIndex, targetIndex)
  ```

  ```java Java theme={"system"}
  // Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`
  SearchClient sourceClient =
    DefaultSearchClient.create("SOURCE_APP_ID", "SOURCE_API_KEY");

  SearchIndex<Record> sourceIndex =
    sourceClient.initIndex("indexNameSrc", Record.class);

  SearchClient targetClient =
  DefaultSearchClient.create("TARGET_APP_ID", "TARGET_API_KEY");

  SearchIndex<Record> targetIndex =
    targetClient.initIndex("indexNameDest", Record.class);

  AccountClient accountClient = new AccountClient();

  // This method throws an exception, if `targetIndex` exists
  accountClient.copyIndex(sourceIndex, targetIndex);

  // Asynchronous
  accountClient.copyIndexAsync(sourceIndex, destinationIndex);
  ```

  ```js JavaScript theme={"system"}
  const algoliasearch = require('algoliasearch');
  // Extra package: `npm install @algolia/client-account`
  const accountCopyIndex = require('@algolia/client-account').accountCopyIndex;

  // Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`
  const sourceIndex = algoliasearch('SOURCE_APP_ID', 'SOURCE_API_KEY').initIndex('indexNameSrc');
  const targetIndex = algoliasearch('TARGET_APP_ID', 'TARGET_API_KEY').initIndex('indexNameDest');

  // This method returns an error if `targetIndex` exists
  accountCopyIndex(sourceIndex, targetIndex);
  ```

  ```kotlin Kotlin theme={"system"}
  // Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`
  val sourceIndex = ClientSearch(
      ApplicationID("SOURCE_APP_ID"),
      APIKey("SOURCE_API_KEY")
  ).initIndex(IndexName("indexNameSrc"))

  val targetIndex = ClientSearch(
      ApplicationID("TARGET_APP_ID"),
      APIKey("TARGET_API_KEY")
  ).initIndex(IndexName("indexNameDest"))

  // This method throws an exception if `targetIndex` exists
  ClientAccount.copyIndex(sourceIndex, targetIndex)
  ```

  ```php PHP theme={"system"}
  use \Algolia\AlgoliaSearch\SearchClient;
  use \Algolia\AlgoliaSearch\AccountClient;

  // Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`
  $sourceIndex = SearchClient::create('SOURCE_APP_ID', 'SOURCE_API_KEY')->initIndex('indexNameSrc');
  $targetIndex = SearchClient::create('TARGET_APP_ID', 'TARGET_API_KEY')->initIndex('indexNameDest');

  // This method returns an error if `$targetIndex` exists
  AccountClient::copyIndex($sourceIndex, $targetIndex);
  ```

  ```python Python theme={"system"}
  from algoliasearch.search_client import SearchClient
  from algoliasearch.account_client import AccountClient

  # Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`
  source_index = SearchClient.create(
      "SOURCE_APP_ID", "SOURCE_API_KEY"
  ).init_index("indexNameSrc")

  target_index = SearchClient.create(
      "TARGET_APP_ID", "TARGET_API_KEY"
  ).init_index("indexNameDest")

  # This method throws an exception if `target_index` exists
  AccountClient.copy_index(source_index, target_index)
  ```

  ```ruby Ruby theme={"system"}
  require 'algolia'

  # Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`
  source_index = Algolia::Search::Client.create(
    'SOURCE_APP_ID', 'SOURCE_API_KEY'
  ).init_index('indexNameSrc')
  target_index = Algolia::Search::Client.create(
    'TARGET_APP_ID', 'TARGET_API_KEY'
  ).init_index('indexNameDest')

  # This method returns an error if `target_index` exists
  Algolia::Account::Client.copy_index(source_index, target_index)
  ```

  ```swift Swift theme={"system"}
  import AlgoliaSearchClient

  // Copy `indexNameSrc` from app `SOURCE_APP_ID` to app `TARGET_APP_ID`
  let sourceIndex = SearchClient(appID: "SOURCE_APP_ID", apiKey: "SOURCE_API_KEY").index(withName: "indexNameSrc")
  let targetIndex = SearchClient(appID: "TARGET_APP_ID", apiKey: "TARGET_API_KEY").index(withName: "indexNameDest")

  try AccountClient.copyIndex(source: sourceIndex, destination: targetIndex) { result in
    if case .success(let response) = result {
      print("Response: \(response)")
    }
  }
  ```
</CodeGroup>

## Parameters

<ParamField body="indexDest" type="object" required>
  Destination index object.
</ParamField>

<ParamField body="indexNameDest" type="string" required>
  Name of the destination index.
</ParamField>

<ParamField body="indexNameSrc" type="string" required>
  Name of the source index to copy.
</ParamField>

<ParamField body="indexSrc" type="object" required>
  Source index object.
</ParamField>

<ParamField body="scope" type="list">
  An array containing any combination of the following strings:

  * `settings`
  * `synonyms`
  * `rules`

  See more on [how this parameter works](#scopes).
</ParamField>

## Response

<ResponseField name="taskID" type="integer">
  This is the taskID which is used with the [`waitTask`](/doc/libraries/sdk/v1/methods/wait-task) method.

  **Note:** You can use either the source or destination index to
  wait on the resulting taskID. In either case, the wait will include
  the full copy process.
</ResponseField>

<ResponseField name="updatedAt" type="date string">
  Date at which the job to copy the index has been created.
</ResponseField>

### Response as JSON

This section shows the JSON response returned by the API.
Each API client wraps this response in language-specific objects, so the structure may vary.
To view the response, use the `getLogs` method.
Don't rely on the order of properties—JSON objects don't preserve key order.

```jsonc JSON icon=braces theme={"system"}
{
  "updatedAt": "2017-12-18T21:22:40.761Z",
  "taskID": 19541511530
}
```
