---
title: "Switch Commerce indexes during rebuild"
slug: "switch-commerce-indexes-during-rebuild"
abstract: "How to ensure high availability of search capability during full rebuilding of Commerce indexes by setting up the Switch on Rebuild on your custom indexes."
---
# Switch Commerce indexes during rebuild

You use the SwitchOnRebuild feature to ensure high availability of search capability during full rebuilding of Commerce indexes. The SwitchOnRebuild feature prevents downtime of search capability, for example, allowing users to continue searching for items, while a complete search index rebuild is in progress.

You can use the SwitchOnRebuild feature with the Solr or SolrCloud search provider.

> [!note]
> The SwitchOnRebuild feature is enabled by default on the following Commerce indexes: CatalogItemsScope, CustomersScope, OrdersScope, PromotionsScope, and PriceCardsScope.

The SwitchOnRebuild feature relies on a primary and a secondary instance of the same index. When you run the [full index minion](https://doc.sitecore.com/xp/en/developers/103/sitecore-experience-commerce/indexing-minions.html "Indexing minions") to rebuild your search index with the SwitchOnRebuild feature enabled, the index rebuilding process occurs on a secondary (non-live) index, while the primary (active) index continues to provide search capability on the live storefront site. Once the rebuilding of the secondary index completes, the indexes switch and the newly rebuilt index becomes the active search index.

## Set up your custom Commerce index to switch on rebuild

You can set up custom indexes in your Commerce deployment to switch on rebuild.

### Create a duplicate of the Solr core to use as the secondary index

If you use Solr as your search provider, you must manually create the secondary index necessary for the switch to occur. You create the secondary index by making a duplicate of the active Solr core.

> [!note]
> If your Commerce deployment uses SolrCloud as a search provider, you do not need to create a secondary index manually (they are created automatically). However, you must [configure SwitchOnRebuild](https://doc.sitecore.com/xp/en/developers/103/sitecore-experience-commerce/switch-commerce-indexes-during-rebuild.html#UUID-56ebfd43-4a38-35a7-b2d9-5ad4f599cd17_N1568395253827 "Configure SwitchOnRebuild for a custom Commerce index") for your custom index.

To duplicate a Solr core:

1. Open the folder containing your Solr core, for example, `C:\solr-8.1.1\server\solr`, and create a sub-folder (for example, *YOURCOREFOLDER-Rebuild*).
2. Open the folder `C:\solr-*.*.*\server\solr\configsets\sample_techproducts_configs`, and copy the *conf* folder in the sub-folder you created in [step 1](https://doc.sitecore.com/xp/en/developers/103/sitecore-experience-commerce/switch-commerce-indexes-during-rebuild.html#UUID-56ebfd43-4a38-35a7-b2d9-5ad4f599cd17_N1568394759412) (for example, `C:\solr-*.*.*\server\solr\YOURCOREFOLDER-Rebuild`).
3. Open the folder that contains the Solr schema of the active core, for example the `SolrSchemas/YOURCORE` folder.

    > [!note]
    > Sitecore XC Solr schemas are available in the SolrSchemas folder of the SolrSchemas.Sitecore.Commerce.x.x.x zip file, included in the Sitecore XC release package.

4. Copy the files `managed-schema` and `solrconfig.xml` to the *conf* folder you create in [step 2](https://doc.sitecore.com/xp/en/developers/103/sitecore-experience-commerce/switch-commerce-indexes-during-rebuild.html#UUID-56ebfd43-4a38-35a7-b2d9-5ad4f599cd17_N1568391940783) (for example `C:\solr-*. *.*\server\solr\YOURCOREFOLDER-Rebuild\YOURCORENAME\conf`).
5. Open a browser window, and in the URL, replace the value used for `"name="` with the name of the new core to create, for example `https://localhost:8994/solr/admin/cores?action=name=YOURCORENAME&configset=sample_techproducts_configs&property.update.autoCreateFields=false`, and then browse to that URL. Now that you have created the new core, you can [configure SwitchOnRebuild](https://doc.sitecore.com/xp/en/developers/103/sitecore-experience-commerce/switch-commerce-indexes-during-rebuild.html#UUID-56ebfd43-4a38-35a7-b2d9-5ad4f599cd17_N1568395253827 "Configure SwitchOnRebuild for a custom Commerce index").

### Configure SwitchOnRebuild for a custom Commerce index

To configure SwitchOnRebuild:

> [!note]
> If you use Solr as your search provider, you must [create a duplicate of the active Solr core](https://doc.sitecore.com/xp/en/developers/103/sitecore-experience-commerce/switch-commerce-indexes-during-rebuild.html#UUID-56ebfd43-4a38-35a7-b2d9-5ad4f599cd17_section-5d7bad2412741-idm45577711313728 "Create a duplicate of the Solr core to use as the secondary index") before your enable the SwitchOnRebuild feature.

1. Open the `wwwroot\data\Environments\PlugIn.Search.PolicySet-1.0.0.json` file, and locate the section that contains the configuration of the active index. For example:

    ```csharp
    {
     "$type":  "Sitecore.Commerce.Plugin.Search.SearchScopePolicy, Sitecore.Commerce.Plugin.Search",
     "Name": "YOURCORENAME",
    {
    ```

2. Define the configuration parameters for your core. As an example, the following shows the configuration of the CatalogItemsScope index with SwitchOnRebuild enabled.

    ```csharp
    {
     "$type":  "Sitecore.Commerce.Plugin.Search.SearchScopePolicy, Sitecore.Commerce.Plugin.Search",
     "Name": "CatalogItemsScope",
     "CurrentIndexName":"CatalogItemsScope",
     "SwitchOnRebuild": true,
     "SwitchOnRebuildReset": false,
     "SwitchOnRebuildClearPreviousIndex": true,
     "SwitchOnRebuildPrimaryIndexName":"CatalogItemsScope",
     "SwitchOnRebuildSecondaryIndexName":"CatalogItemsScope-Rebuild",
    }
    ```

#### SwitchOnRebuild configuration parameters

The following table describes the configuration parameters for the switch on rebuild feature:

| Parameter | Description |
| --- | --- |
| Name | The name of the index. |
| CurrentIndexName | The name (string) of the search index that is currently active. |
| SwitchOnRebuild | Enables or disables the SwitchOnRebuild feature for full index rebuilding operations.<br><br>Default: true |
| SwitchOnRebuildPrimaryIndexName | Name of the primary index. Determines which index to fully rebuild by alternating, and then sets the `CurrentIndexName` property in the SearchStatus entity to persist if rebuilt successful. |
| SwitchOnRebuildSecondaryIndexName | Name of the secondary index. Determines which index to fully rebuild by alternating , and then sets the `CurrentIndexName` property in the SearchStatus entity to persist if rebuilt successful. |
| SwitchOnRebuildClearPreviousIndex | When enabled, deletes all documents in the previous index after the switch.<br><br>Default: true |