Switch Solr indexes

The content rendered on the Website should not be affected by index rebuild. A solution to that is to setup Solr in a way that it will rebuild an index in a separate core so that the rebuilding does not affect the search index that is currently used. Once the rebuilding and the optimization of the index completes, Sitecore switches the two cores, and the rebuilt and optimized index is used.

I will describe the implementation steps with Sitecore 8.2 and Solr 5.3.1. I don’t expect this to be different with newer version.

Duplicate Solr index

Copy index folder (1) and rename it by adding _rebuild (2)  suffix to the original name.

1. Copy

Figure 1 Copy index folder

Update Core configuration file

2. Core

Figure 2 New index Folder

Open core.properties file from new _rebuild index folder (Figure 2 New Index Folder) and change name property to new index name  (Figure 3 New Index core properties file).

3. CORE EDIT

Figure 3 New Index properties file

Add new core to Solr

Steps to add a new index to Solr (Figure 4 Adding new index to Solr)

  1. Open Solr console
  2. Go to Core Admin tab
  3. Click on Add Core button
  4. Paste new Index Folder Name (index will have the same name as its folder )
  5. Paste new Index Folder Name
  6. Click on Add Core button
4. Solr Console

Figure 4 Adding new index to Solr

Verify if primary and secondary indexes work by visiting these URLs:

http://localhost:8983/solr/%5Bindex_name%5D/select/?q=*

http://localhost:8983/solr/%5Bindex_name%5D_rebuild/select/?q=*

For exemple

Separate cores for each index in Sitecore

5. Sitecore Config

Figure 5 Modify Sitecore Index Configuration

Steps to modify

  1. Open Index definition configuration file
  2. Replace the SolrSearchIndex class by its extended SwitchOnRebuildSolrSearchIndex class
  3. Add rebuild core param with <param desc=”rebuildcore”>$(id)_rebuild</param> param between <param desc=”core”>$(id)</param> and <param desc=”propertyStore” ref=”contentSearch/indexConfigurations/databasePropertyStore” param1=”$(id)” />

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s