By: Koen Vlaswinkel
Written in collaboration with Solr
Solr is a search engine platform based on Apache Lucene. It is written in Java and uses the Lucene library to implement indexing. It can be accessed using a variety of REST APIs, including XML and JSON. This is the feature list from their website:
- Advanced Full-Text Search Capabilities
- Optimized for High Volume Web Traffic
- Standards Based Open Interfaces – XML, JSON and HTTP
- Comprehensive HTML Administration Interfaces
- Server statistics exposed over JMX for monitoring
- Linearly scalable, auto index replication, auto failover and recovery
- Near Real-time indexing
- Flexible and Adaptable with XML configuration
- Extensible Plugin Architecture
In this article, we will install Solr using its binary distribution.
To follow this tutorial, you will need:
Step 1 — Installing Java
Solr requires Java, so in this step, we will install it.
The complete Java installation process is thoroughly described in this article, but we’ll use a slightly different process.
First, use apt-get to install
- sudo apt-get install python-software-properties
Instead of using the
default-jre packages, we’ll install the latest version of Java 8. To do this, add the unofficial Java installer repository:
- sudo add-apt-repository ppa:webupd8team/java
You will need to press
ENTER to accept adding the repository to your index.
Then, update the source list:
Last, install Java 8 using apt-get. You will need to agree to the Oracle Binary Code License Agreement for the Java SE Platform Products and JavaFX.
- sudo apt-get install oracle-java8-installer
Step 2 — Installing Solr
In this section, we will install Solr 5.2.1. We will begin by downloading the Solr distribution.
First, find a suitable mirror on this page. Then, copy the link of
solr-5.2.1.tgz from the mirror. For example, we’ll use
Then, download the file in your home directory:
Next, extract the service installation file:
- tar xzf solr-5.2.1.tgz solr-5.2.1/bin/install_solr_service.sh –strip-components=2
And install Solr as a service using the script:
- sudo bash ./install_solr_service.sh solr-5.2.1.tgz
Finally, check if the server is running:
You should see an output that begins with this:
Solr status output
Found 1 Solr nodes:
Solr process 2750 running on port 8983
. . .
Step 3 — Creating a Collection
In this section, we will create a simple Solr collection.
Solr can have multiple collections, but for this example, we will only use one. To create a new collection, use the following command. We run it as the Solr user in this case to avoid any permissions errors.
- sudo su – solr -c “/opt/solr/bin/solr create -c gettingstarted -n data_driven_schema_configs”
In this command,
gettingstarted is the name of the collection and
-n specifies the configset. There are 3 config sets supplied by Solr by default; in this case, we have used one that is schemaless, which means that any field can be supplied, with any name, and the type will be guessed.
You have now added the collection and can start adding data. The default schema has only one required field:
id. It has no other default fields, only dynamic fields. If you want to have a look at the schema, where everything is explained clearly, have a look at the file
Step 4 — Adding and Querying Documents
In this section, we will explore the Solr web interface and add some documents to our collection.
When you visit
http://your_server_ip:8983/solr using your web browser, the Solr web interface should appear:
The web interface contains a lot of useful information which can be used to debug any problems you encounter during use.
Collections are divided up into cores, which is why there are a lot of references to cores in the web interface. Right now, the collection
gettingstarted only contains one core, named
gettingstarted. At the left-hand side, the Core Selector pull down menu is visible, in which you’ll be able to select
gettingstarted to view more information.
After you’ve selected the
gettingstarted core, select Documents. Documents store the real data that will be searchable by Solr. Because we have used a schemaless configuration, we can use any field. Let’sl add a single document with the following example JSON representation by copying the below into theDocument(s) field:
"president": "George Washington",
"party": "No Party"
Click Submit document to add the document to the index. After a few moments, you will see the following:
Output after adding Document
You can add more documents, with a similar or a completely different structure, but you can also continue with just one document.
Now, select Query on the left to query the document we just added. With the default values in this screen, after clicking on Execute Query, you will see 10 documents at most, depending on how many you added:
There are many more options available, but you have now successfully installed Solr and can start using it for your own site.