How to Install, Configure and Use Apache 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 (e.g. XML and JSON). This is the feature

  • 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, I will show you how to install Solr on Ubuntu using two different methods. The first one will be the simple method and the second the more advanced method. I recommend the second method because it installs a newer version of Solr on all Ubuntu versions, even in the most recent version 14.04 at time of writing.

Installing Solr using apt-get (easy way)

sudo apt-get -y install openjdk-7-jdk

mkdir /usr/java

ln -s /usr/lib/jvm/java-7-openjdk-amd64 /usr/java/default

sudo apt-get -y install solr-tomcat

Installing Solr Manually

sudo apt-get -y install openjdk-7-jdk

mkdir /usr/java

ln -s /usr/lib/jvm/java-7-openjdk-amd64 /usr/java/default

We can now start the real installation of Solr. First, download all files and uncompress them:

cd /opt


tar -xvf solr-4.7.2.tgz

cp -R solr-4.7.2/example /opt/solr

cd /opt/solr

/opt/solr/bin/solr start

Check if it works by visiting http://YOUR_IP:8983/solr

How to create a document collection

bin/solr create -c gettingstarted   # this creates a document collection called “gettingstarted”

How to do Indexing

bin/post -c gettingstarted docs/

bin/post -c gettingstarted example/exampledocs/*.xml

bin/post -c gettingstarted example/exampledocs/books.json

bin/post -c gettingstarted example/exampledocs/books.csv

Searching in Apache Solr

You can search using simple json queries by using curl

curl “http://localhost:8983/solr/gettingstarted/select?q=*%3A*&wt=json&indent=true”

curl “http://localhost:8983/solr/gettingstarted/select?q=*:*&wt=json&indent=true”

Search for single term

curl “http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=foundation”

curl “http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=foundation&fl=id”

curl “http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=name:foundation”

Phrase Search

curl “http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=\”CAS+latency\””

curl “http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=%2Bone+%2Bthree”

curl “http://localhost:8983/solr/gettingstarted/select?wt=json&indent=true&q=%2Btwo+-one”


Add a Comment

Your email address will not be published. Required fields are marked *