How to have two (and more) instances of Sitecore pointing to one Solr server

You have probably came across a requirement to have  two or more instances of Sitecore pointing or using same Solr server. This requirement is typical when you use same (virtual) machine to develop more than one Sitecore implementations or you have Habitat or Habitat Home as second Sitecore instance to inspire.

Sitecore 7 & 8

With Sitecore 7 or 8 this requirement was pretty tough to achieve as usually during instantiating a new Sitecore instance using SIM or by different ways, names of cores for Solr that were created / you created were having same name as index name itself so for “sitecore_master_index” Sitecore index, Solr core with same name “sitecore_master_index” was created.

You had to manually change “core” param to your customly made Solr indexes usually with instance prefix.

So for each SOLR core definition you will keep core name (name parameter) and id the same (id attribute).

Normally config would look like this:

<index id="sitecore_master_index" .....>
   <param desc="name">$(id)
   <param desc="core">$(id)

You will just specify “core” parameter as follows:

instance1_$(id) or instance2_$(id) as you need based on instance name.

So config in your case would look like this at the end:

<index id="sitecore_master_index" .....>
   <param desc="name">$(id)
   <param desc="core">instancename_$(id)

or it also can be like this (without sitecore_ in the middle as it is redundant and makes core name unneccesarily too long):

<index id="sitecore_master_index" .....>
   <param desc="name">$(id)
   <param desc="core">instancename_master_index

 

For each solution you will have then config files for solr with same file name, solr ids and all the remaining settings. Only difference will be this “core” parameter.

Here is the patch config to apply your instance settings per solr core:

<index id="sitecore_core_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
   <param desc="core" patch:instead="param[@desc='core']">instancename_$(id>

<index id="sitecore_master_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
   <param desc="core" patch:instead="param[@desc='core']">instancename_$(id>

<index id="sitecore_web_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
   <param desc="core" patch:instead="param[@desc='core']">instancename_$(id>

<index id="sitecore_marketingdefinitions_master" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
   <param desc="core" patch:instead="param[@desc='core']">instancename_$(id>

<index id="sitecore_marketingdefinitions_web" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
   <param desc="core" patch:instead="param[@desc='core']">instancename_$(id>

<index id="sitecore_marketing_asset_index_master" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
   <param desc="core" patch:instead="param[@desc='core']">instancename_$(id>

<index id="sitecore_marketing_asset_index_web" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
   <param desc="core" patch:instead="param[@desc='core']">instancename_$(id>

<index id="sitecore_testing_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
   <param desc="core" patch:instead="param[@desc='core']">instancename_$(id>

<index id="sitecore_suggested_test_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
   <param desc="core" patch:instead="param[@desc='core']">instancename_$(id>

<index id="sitecore_fxm_master_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
   <param desc="core" patch:instead="param[@desc='core']">instancename_$(id>

<index id="sitecore_fxm_web_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
   <param desc="core" patch:instead="param[@desc='core']">instancename_$(id>

Do not forget about added SXA indexes also if you will have them in the future and also for CD servers, you need to remove master indexes from the list.

Sitecore 9

For Sitecore 9 setup, it is much easier as the only two things you need to do is to specify “CorePrefix” parameter for xdb/xconnect and sitecore Solr cores as follows:

#define parameters 
$prefix = "sc9u2" 
$PSScriptRoot = "C:\resourcefiles\"
$XConnectCollectionService = "$prefix.xconnect" 
$sitecoreSiteName = "$prefix.sc" 
$SolrUrl = "https://localhost:8984/solr" 
$SolrRoot = "C:\Solr\solr-6.6.2\" 
$SolrService = "Solr" 
$SqlServer = ".\" 
$SqlAdminUser = "sa" 
$SqlAdminPassword= "saP4$$" 

#install solr cores for xdb 
$solrParams = 
@{     
    Path = "$PSScriptRoot\xconnect-solr.json"     
    SolrUrl = $SolrUrl     
    SolrRoot = $SolrRoot     
    SolrService = $SolrService     
    CorePrefix = $prefix 
} 

Install-SitecoreConfiguration @solrParams -Verbose 

#install solr cores for sitecore $solrParams = 
$solrParams = @{     
    Path = "$PSScriptRoot\sitecore-solr.json"     
    SolrUrl = $SolrUrl     
    SolrRoot = $SolrRoot     
    SolrService = $SolrService     
    CorePrefix = $prefix 
} 

Install-SitecoreConfiguration @solrParams 

I usually specify $prefix and that parameter will determine name of Sitecore/XConnect instance and also it will be used for all Solr cores.

Above is only part of the script to demonstrate how to set CorePrefix parameter to Solr cores.

Full script can be found here -> https://github.com/chorpo/Sitecore9Installation/blob/master/01%20Install.ps1

Summary

In code you will reuse everything as you have as you are referencing solr index ids so you will still reference “sitecore_master_index” or “sitecore_web_index” but based on the deployed configuration in each instance, you will effectively reference different Solr cores based on instance name.

To identify Sitecore Solr cores quickly, you can go to ShowConfig admin page and search for <indexes hint="list:AddIndex".

You will see all (11 for Sitecore 9) out of the box indexes and their respective configuration. You can quickly identify files in which are patched:

enter image description here

Happy indexing and searching!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s