Sitecore’s SwitchOnRebuild with Managed Search


The SearchStax Managed Search service is compatible with Sitecore’s SwitchOnRebuild.

Sitecore indexes frequently have massive content with high turnover. Solr’s usual update mechanism—deleting and adding individual records followed by segment merging—is not adequate on this scale. It is much more efficient to dump Sitecore’s current state into a new index file. This can take hours, during which the collection is unavailable for search.

Enter SwitchOnRebuild. This feature, available since Sitecore 8.2, lets Sitecore build a new Solr index while serving queries from the previous index. When the new core is ready, Sitecore makes it active and deletes the old core.

SwitchOnRebuild for Sitecore 10+

The Managed Search Connector makes it easy to configure SwitchOnRebuild for Sitecore 10+. Both standard and custom indexes can be configured as part of the initial Sitecore-to-Solr setup including SwitchOnRebuild if desired.

See, for instance, How to Integrate Apache Solr with Sitecore 10.3 using the Managed Search Connector for Sitecore.

Overview

People usually enable switchOnRebuild for these three Sitecore indexes:

  • sitecore_master_index
  • sitecore_core_index
  • sitecore_web_index

Setting up switchOnRebuild for a Sitecore index in Managed Search involves two activities:

  • Setting up the _rebuild collections and aliases in Solr.
  • Enabling switchOnRebuild on the Sitecore side.

Create Solr Collections

On the Solr side, you must log into the Solr Dashboard and create a _rebuild collection for each of the modified indexes.

  • sitecore_master_index_rebuild
  • sitecore_core_index_rebuild
  • sitecore_web_index_rebuild

Access the Solr Dashboard and select Collections in the left-hand menu. Click Add Collection.

For the name of the new collection, use the Sitecore index name and add _rebuild, as in sitecore_master_index_rebuild. The new collection should use the same configset as the original index. ReplicationFactor should be the number of nodes in your cluster. Our advice is to always leave numShards set to 1.

Click the Add Collection button.

Repeat this procedure for the remaining two indexes.

Create Solr Aliases

Now it’s time to build your aliases in the same Collections screen of the Solr Dashboard.

Look for the Create Alias button. In older versions of Solr, this button is at the top of the screen. In recent Solr releases, the button is at the bottom of the screen. Click this button.

To name the alias, use the name of the Sitecore index and append “_MainAlias”, as in sitecore_master_index_MainAlias. Then select the Sitecore index from the scrolling list and click the (new) Create Alias button.

Repeat three times, so you have a “_MainAlias” for each Sitecore index.

Now we need three more aliases. Repeat the steps for the three Sitecore indexes, but use the “_RebuildAlias” suffix instead of the “_MainAlias” suffix.

When you finish, you should see these nine new objects in your Collections screen:

Enable SwitchOnRebuild in Sitecore

To enable switchOnRebuild for these three indexes, please download SwitchOnRebuildSolrCloud.config from the SearchStax website. It arrives as a ZIP file, so you must extract the config file before use.

The file does not need to be modified for Sitecore 10.x. It is ready to run. Note that this config is for the SolrCloud version of switchOnRebuild, not the stand-alone version.

Drop a copy of this file anywhere beneath the App_Include folder in each of your Sitecore Instances (CM, CD, Processing, and Reporting). Each instance will detect the change in the configuration and will restart.

Build the Indexes

Within the Sitecore Experience Platform, click on the Control Panel, and then click on Index Manager. Verify that you can see all three of the modified indexes in the list. (If something is missing, it indicates a configuration issue.) Select the modified indexes and rebuild them.

Troubleshooting SwitchOnRebuild

In cases where there’s a suspected issue around swapping indexes, it’s almost always a configuration issue where the alias name is either misspelled or the parameter ordering is wrong in the configs.
 
When that’s not the case, it’s generally some sort of connection issue with Solr, which would be highlighted in the logs in the form of an application error in the Sitecore log.

Other SearchStax Pages

The current page supersedes our previous blog post, Sitecore SwitchOnRebuild and SearchStax SolrCloud.

We have a discussion of why your local-node SwitchOnRebuild configuration won’t work with SolrCloud: Can we use Sitecore’s SwitchOnRebuild with SearchStax?

You should also be aware of Why does Sitecore fail to populate schemas?

Questions?

Do not hesitate to contact the SearchStax Support Desk.