Setting up multiple cores in SOLR can seem like a daunting task but is pretty simple. You’ll need to create a
solr.xml file, create a directory to contain the core specific infomration, and modify some configuration files.
Create a solr.xml file
I created a
solr.xml file in
$SOLR_HOME that tells SOLR the path to the core directories and the names of the cores.
If the new core directory is called
solr.xml will look something like this:
<?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" sharedLib="lib"> <!-- adminPath: RequestHandler path to manage cores. If 'null' (or absent), cores will not be manageable via REST --> <cores adminPath="/admin/cores"> <!-- name: public name that will appear in the url --> <!-- instanceDir: name of the directory containing the core's data and conf directories --> <core name="core-qa" instanceDir="<strong>core-questions-answers</strong>"/> </cores> </solr>
Create a directory to contain core specific information
I then created the directory
core-questions-answers in the same directory as the
solr.xml file. This directory will store information specific to the new core. I then created 2 directories under the
core-questions-answers directory; a
data directory to store the index/segment files; a
conf directory containing the configuration files that are specific to the core.
The directory structure will look something like this:
solr.xml core-questions-answers ├── conf │ ├── admin-extra.html │ ├── data-config.xml │ ├── elevate.xml │ ├── protwords.txt │ ├── schema.xml │ ├── scripts.conf │ ├── solrconfig.xml │ ├── spellings.txt │ ├── stopwords.txt │ ├── synonyms.txt │ └── xslt │ ├── example.xsl │ ├── example_atom.xsl │ ├── example_rss.xsl │ └── luke.xsl └── data ├── index │ ├── _0.cfx │ ├── _a.cfs │ ├── segments.gen │ └── segments_2 ├── spellchecker1 │ ├── segments.gen │ └── segments_1
The files in
core-questions-answers/data/index in the example above are the index/segment files. Those won’t appear until an index has been generated. I include them above to give an idea of what the files might look like (there will be
segments* files but the other files may have different names/extensions).
Modify configuration files
When creating a core for the first time I usually copy all the configuration files found in
example/solr/conf/ of the SOLR distribution to
core-questions-answers/conf. There are 2 configuration files I work with most;
solrconfig.xml file is where you’ll find the the various handlers, writers, caches and their settings.
schema.xml is where elements such as data types and field names can be found. You can almost think of
schema.xml file as what you might find in a database schema.
If you index this core using the Data Import Handler then you’ll also need to modify the
data-config.xml file. Note that every time the core is indexed using the DIH a new file called
dataimport.properties will be created by SOLR which basically stores the last time the core was indexed.