Apache Solr Clustering Example
In this article, we will demonstrate an Apache Solr Clustering Example. We are going to show you how to set up and run a SolrCloud with two Solr servers and an embedded ZooKeeper instance on your local machine.
Once it is up and running, we will show you how to use it to index our sample article collection and how to do a basic search.
1. What is a Apache Solr cluster?
A cluster is a group of servers working together as one system. An Apache Solr cluster is called SolrCloud which consists of a cluster of Solr servers. It provides capabilities for distributed search and indexing with fault tolerance and high availability.

As we can see from the diagram above, SolrCould doesn’t have a master node to allocate other slave nodes, shards, and replicas. Instead, Apache ZooKeeper is used to manage the entire cluster’s information such as Solr servers’ addresses, ports, etc. in a centralized way. In the production environment, normally a ZooKeeper cluster will be used to guarantee high availability. As SolrCloud works as one system, queries and updates can be sent to any Solr server of the cluster. SolrCloud will use the information stored in ZooKeeper to figure out which servers need to handle the request.
The steps and commands described in this example are for Apache Solr 8.5 on Windows 10. The JDK version we use to run the SolrCloud in this example is OpenJDK 13. Before we start, please make sure your computer meets the system requirements. Also, please download the binary release of Apache Solr 8.5.
2. Run a SolrCloud Locally
2.1 Unzip Solr
Unzip solr-8.5.2.zip to a local directory and change your working directory to the sub-directory where Solr is unpacked. For example, on Windows, we unzip solr-8.5.2.zip to the directory “D:\Java” and then “cd D:\Java\solr-8.5.2”. The directory layout is shown below:

For more details, please check out the directory layout page.
2.2 Lauch SolrCloud
To launch Solr in SolrCloud mode, run: bin\solr.cmd start -c on Windows; bin/solr start -c on Unix or macOS.
Firstly, let’s start the first Solr server on the default port 8983 in SolrCloud mode. When starting in SolrCloud mode without specifying the ZooKeeper instance to connect to, an embedded ZooKeeper instance is started on Solr port + 1000, such as 9983 if Solr is bound to 8983. Open a Command Prompt on Windows, change your working directory to the Solr installation directory and run the following command:
bin\solr.cmd start -c
-c means SolrCloud mode. Once the command finishes running, we will see the output below and the first Solr server is up and running on port 8983. Note that as we didn’t provide a ZooKeeper instance to connect to when running in SolrCloud mode, the embedded ZooKeeper instance has also been started on port 9983.
D:\Java\solr-8.5.2>bin\solr.cmd start -c Waiting up to 30 to see Solr running on port 8983 Started Solr server on port 8983. Happy searching!
How do we know the first Solr server and the ZooKeeper are running? An easy way is to use the Solr Admin. Solr Admin is a web-based admin console that can be accessed from browser. It provides several easy-to-use functions for users to check the status and manage Solr instances. Open a browser such as Chrome and type the URL http://localhost:8983/solr/ in the address bar. We can see the dashboard page of Solr Admin as below:

Then, we can start the second Solr server on another port 8984 other than the default port 8983 in SolrCloud mode. To let the second Solr server join the cluster with the first Solr server, we need to specify the ZooKeeper instance to connect to. Because the embedded ZooKeeper instance has already been running after the previous step, we can simply add -z localhost:9983 to the command as below:
bin\solr.cmd start -c -p 8984 -z localhost:9983
Once the command finishes running, we will see the output below and the second Solr server is up and running on port 8984.
D:\Java\solr-8.5.2>bin\solr.cmd start -c -p 8984 -z localhost:9983 Waiting up to 30 to see Solr running on port 8984 Started Solr server on port 8984. Happy searching!
Now we have started two Solr servers and one ZooKeeper instance on our local machine. To verify everything is working as expected, open Solr Admin and navigate to the “Cloud –> Nodes” section from the navigation menu on the left side of the screen.

We can see that there are two Solr nodes running on port 8983 and 8984 on the local machine with some statistics. Also, we can check out the status of the ZooKeeper instance as below by clicking the “ZK Status” menu item.

3. Indexing Data
3.1 Create a Collection
A collection is a complete logical index in a SolrCloud cluster which is used for indexing data. We can refer to it by the collection name. It has a config set and contains one or more shards. If the number of shards is more than one, it is a distributed index.
There are a few ways to create a new collection in SolrCloud. For example, we can use the Download NOW!







