In this tutorial, I will guide you through the process of configuring your Apache Solr to run with multiple cores. This can be useful if you are using Apache Solr with multiple different projects, and need complete separation between the two projects' search indexes.

This tutorial assumes that you are running Apache Solr on Jetty Web Server, and have both set up in the same manner as described in the following tutorials:

How to Install Jetty Web Server in Ubuntu

How to Install Apache Solr in Ubuntu

Edit solr.xml

cd /opt/jetty/solr
sudo gedit solr.xml

If you haven't done any modifications to your current solr.xml file, then use the following as a template:

<?xml version="1.0" encoding="UTF-8" ?>
<!--
 All (relative) paths are relative to the installation path
  
  persistent: Save changes made via the API to this file
  sharedLib: path to a lib directory that will be shared across all cores
-->
<solr persistent="false">

  <!--
  adminPath: RequestHandler path to manage cores.  
    If 'null' (or absent), cores will not be manageable via request handler
  -->
  <cores adminPath="/admin/cores">
    <core name="core0" instanceDir="./cores/core0" />
    <core name="core1" instanceDir="./cores/core1" />
  </cores>
</solr>

The import parts of this file are the core tags.

Create Cores Directory

Create a new directory within the solr directory to keep all the cores organized:

cd /opt/jetty/solr
sudo mkdir cores

Configure First Core

We're going to use the default core that ships with Apache Solr 4 as our template:

cd /opt/jetty/solr
sudo cp -R collection1 ./cores/core0

Create a data directory for this core:

cd /opt/jetty/solr/cores/core0
sudo mkdir data

Now edit the solrconfig.xml for this core:

cd /opt/jetty/solr/cores/core0/conf
sudo vim solrconfig.xml

Change the following:

<dataDir>${solr.data.dir:}</dataDir>

To:

<dataDir>/opt/jetty/solr/cores/core0/data</dataDir>

And, change the following:

<str name="dir">${solr.data.dir:}</str>

To:

<str name="dir">/opt/jetty/solr/cores/core0/data</str>

Create Second Core

Copy the first core:

cd /opt/jetty/solr/cores
sudo cp -R core0 core1

Now edit the solrconfig.xml for this core:

cd /opt/jetty/solr/cores/core1/conf
sudo vim solrconfig.xml

Change the following:

<dataDir>${solr.data.dir:}</dataDir>

To:

<dataDir>/opt/jetty/solr/cores/core1/data</dataDir>

And, change the following:

<str name="dir">${solr.data.dir:}</str>

To:

<str name="dir">/opt/jetty/solr/cores/core1/data</str>

Set Owner of Cores Directory

Finally, you'll need to set Jetty as the owner of the cores directory:

cd /opt/jetty/solr
sudo chown -R jetty:jetty cores

Restart Jetty

sudo /etc/init.d/jetty restart

If all is well, you should be able to access the admin page for each core at the following URLs:

core0 -- admin

core1 -- admin

The query URL works similarly:

core0 -- query URL

core1 -- query URL