June 28, 2016

Using Config Transforms to Manage Sitecore Indexes

By: Craig Taylor
June 28, 2016

Using Config Transforms to Manage Sitecore Indexes

In my previous post, I talked about setting up your Solr indexes to use the "SwitchOnRebuildSolrSearchIndex" index type to avoid index downtime.  In that post, I mentioned that I was using Config Transforms in order to manage the configuration settings across my different environments.  Here's a quick example of how to set up an index for the different environments:

The 'Default' or 'Standard' Index configuration that I have in my solution:

What's going on?:

  • I have separate configurations for "Web" vs "Master" databases. This configuration is for the "Web index. 
  •  I'm using the 'onPublishEndAsync' indexing strategy since this is my "Web" database.  This tells Solt to update the index when a publish is complete.

I then "Add Transform" in Visual Studio to create the specific versions for the other environments.

Note: In order to add the tranformations, you have to have separate solution configurations configured for each environment.

I'll skip all my local/dev/qa/stage environments and just show what I've got for production, but note that each environment can and usually *should* have its own transformation.

Production CM server configuration:

What's going on?:

  • I tell the transform to look for all indexes in the parent config file and change the index type to "SwitchOnRebuildSolrSearchIndex."  I like to keep only one index per configuration file, but if you had multiple indexes defined, this will change all of them.
  • I'm inserting the "rebuildcore" parameter into the index configuration.  This is required so that Sitecore knows which Solr core to swap to after the rebuild is complete.  It's also very important that it goes in in the third position as Sitecore expects it there.

When the transformation is applied, it looks like this:

For the Production CD server, I have the following transform:

What's going on?:

  • As with the CM server, I'm changing the index type to "SwitchOnRebuildSolrSearchIndex", but as you will see with the next point, it doesn't really matter.
  • We are setting the index strategy to "manual."  Our Solr indexes are centrally located on another server and we want the indexing to only happen once.  The rebuilding of the indexes are controlled by the actions of the CM server.
Setting up different configurations based on environment is easily accomplished using config transforms.  It keeps your configuration files clean and easy to manage.