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
- Browse to “server\solr\configsets”.
- Make a copy of “_default” configset and rename it to “sitecore_core_index”.
- Login to Sitecore site. Browse to Control Panel.
- From Indexing section click “Generate to Solr Schema.xml file” link.
- For the source file, set path to managed-schema file in “sitecore_core_index” configset.
- 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.
- Click “Generate” button to generate the target schema.xml file.
- Close the dialog once the file is generated.
- 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.
- 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”.
- 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.
- Execute following command to start setup.
solr start –e cloud
- 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.
- Next it will ask for port for node1. We will go with default, i.e. 8983. Press Enter to continue.
- Same for node2 and with accepting default value, press Enter to continue.
- Solr will configure the nodes with given ports and check for their availability during setup.
- 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.
- 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.
- Next it will ask for number of replicas per shard. Go with default value and press Enter to continue.
- Next it will ask for configuration set to select for the collection to be created. Go with default value and press Enter to continue.
- Next, the process continues and creates the collection and completes the setup and startup of Solr in cloud mode.
- You will be presented with the URL for accessing solr through browser.
- Open web browser and hit the given URL to make sure the Solr is working fine.
- 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.
Now it’s time to create the collections. Following are the steps.
- Browse to Solr admin panel.
- Go to “Collections”.
- Click “Add Collection” button.
- Provide name, config set, numShards and replicationFact values as shown in the below image.
- Click “Add Collection” button to create the collection.
- 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.
- Browse to “app_config/include” folder of your Sitecore site.
- Search for “*lucene*”. Rename all the .config files with .config.disabled.
- Search for “*solr*’. Remove “.disabled” or “.example” extensions for the files.
- Open “Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config” file.
- 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.
- Login to Sitecore site.
- Go to Control Panel and click “Indexing manager”.
- In the “Indexing Manager” dialog, make sure you see the indexes listed correctly.
- If you see an empty list, then check your configuration and make changes until you get this list.
- Select the indexes, and click Rebuild so Sitecore content is crawled and uploaded to Solr server.
- Open Sitecore.ContentSearch.config file.
- 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.