Configure SolrCloud for Sitecore

Recently I have to configure Solr in cloud mode for Sitecore website. I search for it through google and found many nice articles explaining steps for the configuration. However, at the end I found that few important steps are not mentioned and hence a person like me who is new to Solr waste his time finding what’s wrong with configuration.

So, in this article I am explaining all the steps for configuring Solr cloud for Sitecore.

I here assume that a Sitecore site with required content is already setup and I am not mentioning any steps for setting up Sitecore site.

I here considered that my solr, version 6.6.0, is located at “C:/solr-6.6.0” location. All directory locations are relative to this location. Please make sure you use appropriate location and modify the commands here provided according to your location.

Prepare Solr configuration for Sitecore usage

  1. Browse to “server\solr\configsets”.
  2. Make a copy of “_default” configset and rename it to “sitecore_core_index”.
  3. Login to Sitecore site. Browse to Control Panel.
  4. From Indexing section click “Generate to Solr Schema.xml file” link.
  5. For the source file, set path to managed-schema file in “sitecore_core_index” configset.
  6. For target file, set path to schema.xml file in “sitecore_core_index” configset. Don’t worry if schema.xml file is not in the directory. It will be created.
  7. Click “Generate” button to generate the target schema.xml file.
  8. Close the dialog once the file is generated.
  9. To make sure the schema.xml file is as expected, open it in text editor and find for “_database” field. You can also see other fields from Sitecore are listed in the file. Close the file once you are done.
  10. Now make copy of “sitecore_core_index” for all the local indexes available in Sitecore Indexing Manager. As of now, we have already done for “sitecore_core_index”.
  11. Now we are pretty set with Solr configuration required for Sitecore search.

Run SolrCloud instance locally

For the development purpose we can configure Solr in cloud mode on local development machine. Following are the steps.

  1. Execute following command to start setup.
solr start –e cloud
  1. Next it will ask for number of nodes you need to create for the local cluster. The default value is 2 and we will continue with this. Just press Enter to continue.
  2. Next it will ask for port for node1. We will go with default, i.e. 8983. Press Enter to continue.
  3. Same for node2 and with accepting default value, press Enter to continue.
  4. Solr will configure the nodes with given ports and check for their availability during setup.
  5. After creating and configuration nodes, it will ask for the collection to create. Again, we will go with default value, i.e. gettingstarted. We will create our own collections later. Press Enter to continue.
  6. Next it will ask for number of shards for the above mentioned collection. Go with default value, i.e. 2 and press Enter to continue.
  7. Next it will ask for number of replicas per shard. Go with default value and press Enter to continue.
  8. Next it will ask for configuration set to select for the collection to be created. Go with default value and press Enter to continue.
  9. Next, the process continues and creates the collection and completes the setup and startup of Solr in cloud mode.
  10. You will be presented with the URL for accessing solr through browser.
  11. Open web browser and hit the given URL to make sure the Solr is working fine.
  12. Click on “Collections” from left navigation to make sure the “gettingstarted” collection is created.

Upload the index configuration into ZooKeeper

So far, we have created index configsets for different indexes available in Sitecore and started the Solr server in cloud mode. Now, we will upload the configsets created earlier into the ZooKeeper.

Solr provides ZooKeeper command-line interface (zkcli) to work with ZooKeeper file system. This cli is located at “server\scripts\cloud-scripts” folder.

Run the following command to upload the Solr configuration into ZooKeeper.

zkcli –zkhost localhost:9983 –cmd upconfig –confdir C:\solr-6.6.0\server\solr\configsets\sitecore_core_index\conf –confname sitecore_core_index

Execute the same above command to register all the configuration which we have created earlier.

Once you are done will registering all the configsets, browse to Solr admin and make sure they are listed under “/configs” on Cloud > Tree page.

Create collections

Now it’s time to create the collections. Following are the steps.

  1. Browse to Solr admin panel.
  2. Go to “Collections”.
  3. Click “Add Collection” button.
  4. Provide name, config set, numShards and replicationFact values as shown in the below image.
  5. Click “Add Collection” button to create the collection.
  6. Repeat steps 3 to 5 for all the remaining configsets.

Enable solr configuration for Sitecore

Now it’s time to enable solr configuration files and disable the lucene configurations.

  1. Browse to “app_config/include” folder of your Sitecore site.
  2. Search for “*lucene*”. Rename all the .config files with .config.disabled.
  3. Search for “*solr*’. Remove “.disabled” or “.example” extensions for the files.
  4. Open “Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config” file.
  5. Set the value for “ContentSearch.Solr.ServiceBaseAddress” setting variable to Solr URL. For example, http://localhost:8983/solr. You may need to change the port according to your configuration.
  6. Login to Sitecore site.
  7. Go to Control Panel and click “Indexing manager”.
  8. In the “Indexing Manager” dialog, make sure you see the indexes listed correctly.
  9. If you see an empty list, then check your configuration and make changes until you get this list.
  10. Select the indexes, and click Rebuild so Sitecore content is crawled and uploaded to Solr server.
  11. Open Sitecore.ContentSearch.config file.
  12. Set value for ContentSearch.SearchMaxResults setting to somewhat 500 (adjust according to your requirement). The default value is empty and hence it uses int.MaxValue which causes issues during query execution and you will not get expected results.

Leave a Reply