Let’s Talk

We would love to hear from you. Want to know more about
our services or have any questions? Say Hi!

Switch on Rebuild index on Docker

May 25, 2022
Switch on Rebuild index on Docker
Mitesh Patel
Mitesh Patel
Technical Head
switch-on-rebuild-index-on-docker

In Sitecore, there is a mechanism for switching between active and rebuild indexes in order to avoid downtime in search functionality on the website. We, therefore, configured the Switch On Rebuild feature for this custom index so that the rebuilding process doesn’t affect the active index used on the live site.

You can set up the SOLR to rebuild an index in a separate core so that the rebuilding does not affect the search index that is currently in use. Once the rebuilding and the optimization of the index is done, Sitecore switches both the cores and the rebuilt, optimized index is used.

The SwitchOnRebuildSolrSearchIndex class inherits from the SolrSearchIndex class and adds the capability of maintaining two cores for a particular index. Because this is only important for production environments, you can reconfigure your custom index with SwitchOnRebuild.

Why this is required?

When we rebuild the Solr index, it deletes all the indexes and then creates new files. During this process, the indexes are not available. This impacts the website’s performance as Search is not available. Also, if any pages are dependent on indexes, those pages will stop working. This can definitely impact the usability of the website.

Here this feature is very helpful. The index is built in a separate index/core. Once the rebuild process completes, Sitecore switches to new index. This suggests minimum downtime.

Docker Solr

Docker Solr runs as SolrCloud. Switch on rebuild functionality has two different approaches, SwitchOnRebuildSolrSearchIndex  and SwitchOnRebuildSolrCloudSearchIndex. So, Docker Solr runs as cloud and we have to use SwitchOnRebuildSolrCloudSearchIndex.

Please find below the steps to configure rebuild index in docker solr.

How to Create new Solrindex using Docker SOLR.

In the docker we have separate containers for SOLR

  • solr init
  • solr

If we want to create a new index in SOLR then please follow the below given steps.

- Add one JSON file in \docker\build\solr-init folder and add your index name E.g., "sitecore_test_index_rebuild" into JSON as per the below screenshot. Here, I have added two indexes.

E.g. file name: cores-test.json (Name as per your convenience)

switch-on-rebuild-index-on-docker-2

- Add path of "cores-test.json" file into dockerfile as per the screenshot.

E.g. COPY cores-test.json C:\data\cores-test.json

switch-on-rebuild-index-on-docker-3

- Remove zoo_data folder from \docker\data\solr\zoo_data

switch-on-rebuild-index-on-docker-4

- Now execute command “docker-compose build” and then “doker-compose up” in powershell. You will get new index in solr folder. (If you added one index in cores-test.json file then you will get one new folder here.)

switch-on-rebuild-index-on-docker-5

Restart solr init container in docker

Check solr to see if you can see new index

switch-on-rebuild-index-on-docker-6

If you require some changes in the configuration level then create a new patch configuration for the SwithonRebuild.

You can get this config from example configs of any of your project from path

App_Config\Include\Examples\

Sitecore.ContentSearch.SolrCloud.SwitchOnRebuild.config.example.

Copy this example config and put it into your App_Config folder and remove extension “example” and do necessary changes as mentioned below.

Config changes as per environment type:

  1. Scale Environment: If you have scale environment then you need to make changes as per the role (Dev,UAT,Production)of environment as per below image.
  2. switch-on-rebuild-index-on-docker-7
  3. Single Environment: If you have single environment type then you need not worry about role-based changes. (Just need to change your index id from config)
  4. switch-on-rebuild-index-on-docker-8

Add all index collection names in SwithonRebuild.config

- Now go to CMS Sitecore >> Control Panel and open Populate Solr Managed Schema.

- Populate your new custom index.

- Go to Index manager and rebuild your new custom index.

Now you can verify your search functionality. On one side your index rebuild is going and on the other side your search functionality is working fine on the website. That is the magic of Switch on Rebuild index. We can use Switch on rebuild functionality on solr cloud, Searchstax etc.


YOU MAY ALSO LIKE