Zero downtime index rebuild in Azure Search

Use the Azure Search Switch On Rebuild feature to avoid Search functionality downtime during a full rebuild of the Sitecore Search index.

Note

This feature is supported from Sitecore versions 8.2.7 and 9.0.2 and later. It does not require any additional configuration and is enabled, by default.

A full index rebuild executes in a separate rebuild index. When the rebuild operation finishes, Sitecore switches the Search service to use the new rebuilt index as the primary search index. After this, Sitecore deletes the previous Search index.

You can control the Switch On Rebuild feature with the following index configuration settings:

  • <setting name="ContentSearch.Azure.SwitchOnRebuild" value="true"/> To avoid downtime of the Search functionality during an index rebuild, use this setting to specify whether the Azure Search provider uses the SwitchOnRebuild functionality. The default value is true.

  • <setting name="ContentSearch.Azure.SwitchOnRebuildCleanUpDelay" value="00:01:00"/> You can set a time buffer to prevent Sitecore deleting the old index before all of the roles have been switched over to work with the newly rebuilt index. The default value is 00:01:00 (1 minute). You can only use this when the SwitchOnRebuild feature is enabled.

After a power user requests a full rebuild of the Sitecore Search index(es), the following process takes place:

  • The Sitecore Azure Search provider creates and populates a new sitecore-master-index for the full rebuild operation, which is used as the primary index.

  • While Sitecore writes data into the new index, the search provider continues to use the old one.

  • When the full rebuild is complete, the Sitecore Azure Search provider sends a corresponding remote event (index:switchonrebuild) to all roles.

  • Each role processes the remote 'index:switchonrebuild' event and switches the search service over to work with the newly rebuilt index.

  • The SwitchOnRebuildCleanUpDelay setting controls the delay that allows other roles to process the remote event and switch index.

  • After the time-buffer delay runs out (controlled by the SwitchOnRebuildCleanUpDelay setting), and the rebuilt index becomes the primary search index, Sitecore deletes the previous search index. This delay allows the other roles time to process the remote event and switch indexes.

    Note

    When a rebuild is scheduled, the Sitecore Azure Search provider creates a secondary index called sitecore-master-index-xxx. When the reindex finishes, the sitecore-master-index-xxx becomes the primary and the sitecore-master-index is deleted after a few minutes, (you can check this in the ContentSearch.Azure.SwitchOnRebuildCleanUpDelay configuration file).

    All index-update operations are postponed during a rebuild process.