How to use Solr with Sitecore 8.2 with Solr 6 – the easy way

Sitecore 8.2 is out! Solr 6.2 is out! Let’s get up running with both!

This is a short and updated version of a previous post on Sitecore and Solr “How to use Solr with Sitecore 8 – the easy way”.

Step 1: Generate the basic Solr schema file from your Sitecore installation

Note: I have created a zip file you can use – so you don’t have to do all these steps really – unless you use another version of Sitecore.

In short – you need to follow these steps if you really want to do this work:

  • Download and install Solr 6 (http://lucene.apache.org/solr/downloads.html)
  • Copy the directory “basic_configs” to create a Sitecore_configs (I copied \solr-6.2.1\server\solr\configsets\basic_configs to \solr-6.2.1\server\solr\configsets\sitecore_configs)
  • Open and edit the managed-schema.xml file by all <fieldTypes> are structured under <types>, and all <field> are structured under <fields>. In short:
<types>
    <fieldType name="string" class="solr.StrField" …..
    …...
</types>
<fields>
    <field name="id" type="string" …..
    …..
</fields>
  • Use the Generate Solr Schema in the Sitecore control panel
  • After the schema.xml is generated, delete the managed-schema.xml
  • Open the solrconfig.xml and add a  ClassicIndexSchemaFactory definition:
<schemaFactory class="ClassicIndexSchemaFactory"/>
  • Open the newly generated schema.xml file and add:
<fieldType name="pint" class="solr.TrieIntField" docValues="true" precisionStep="0" positionIncrementGap="0" /> so it looks like this:

Solr Schema Add FieldType pint

Step 2: Prepare and organize you Solr core structure

I like to have a separation between configuration and data. Sitecore 8.2 has not added any new indexes – so I can use the folder structure from my old post. So for each index we need to create a folder for each of our Sitecore indexes: (Note: you don’t have to do this – you can download the files from this post).

Solr Core File Structure

To create the first core follow these steps:

  • Create a new folder: \solr-6.2.1\server\solr\cores_conf
  • Create a new folder: \solr-6.2.1\server\solr\cores_conf\sitecore_analytics_index
  • Copy the folder \solr-6.2.1\server\solr\configsets\sitecore_configs\conf to the folder: \solr-6.2.1\server\solr\cores_conf\sitecore_analytics_index
  • Create a property file that tells Solr where the configuration files are, and where to place the data files:
    • Create a text file in the sitecore_analytics_index folder and name it: core.properties
    • Make sure that the file has the following line: dataDir=../../cores_data/sitecore_analytics_index
  • Check that Solr locates the core on startup.
  • From here on, it’s just a matter of copying and renaming the core we just created. For each core do the following:
    • Duplicate the sitecore_analytics_index folder. Rename it to [new-core-name]
    • Edit the core.properties in the [new-core-name] folder, change the only line to: dataDir=../../cores_data/[new-core-name]
  • Repeat the process until you have following cores created:

sitecore_analytics_index

sitecore_core_index

sitecore_fxm_master_index

sitecore_fxm_web_index

sitecore_list_index

sitecore_marketing_asset_index_master

sitecore_marketing_asset_index_web

sitecore_marketingdefinitions_master

sitecore_marketingdefinitions_web

sitecore_master_index

sitecore_suggested_test_index

sitecore_testing_index

sitecore_web_index

social_messages_master

social_messages_web

  • Restart Solr and verify that you have all the cores up running in Solr.

Step 3: Patch the configuration to use Solr for all the indexes instead of Lucene

  1. Create a folder “zzzSolrIndexes” and place this in App_Config\Include. In this folder copy all the Solr configuration files that ships with Sitecore as .disabled or .example:
  2. Remove the .example and .disabled from the above files.
  3. Disable all the currently enabled Lucene indexes by a single patch file:

Create a file in our zzzSolrIndexes folder, and ensure that this patch fill will be executed before all your Solr configurations. Name the patch file: aaaSitecore.ContentSearch.DisableAllLuceneIndexes.config

The content of that file is where we simply remove the Lucene indexes – one by one:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
   <sitecore>
      <contentSearch>
         <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
            <indexes hint="list:AddIndex">
               <index id="sitecore_analytics_index" type="Sitecore.ContentSearch.LuceneProvider.LuceneIndex, Sitecore.ContentSearch.LuceneProvider">
                  <patch:delete />
               </index>
               <index id="sitecore_master_index" type="Sitecore.ContentSearch.LuceneProvider.LuceneIndex, Sitecore.ContentSearch.LuceneProvider">
                  <patch:delete />
               </index>

……

Repeat the lines for all the index ids. You can use the lists of the cores we created in the beginning of this blog. You should end up with disabling 15 indexes.

Note: you can download a copy of these files at the end of the post. Just unzip and place it in your include folder.

Step 4: Install the Solr support packages from Sitecore

  • Download the Sitecore support package from Sitecore (Sitecore.Solr.Support 2.0.0 rev. 160726).

There’s support for a number of number of IoC containers. Choose the one that you are comfortable in using, or already uses as part of your project. The packages NO LONGER uses the global.ascx for initiating the Solr provider (nice!).

Copy config file (e.g. Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.IOC.StructureMap.config – remove .example) to the App_Config\Include.

  • Copy the needed DLLs that also was part of Solr Support Package. Example for structuremap:
  • SolrNetIntegration.dll
  • ContentSearch.SolrProvider.StructureMapIntegration.dll
  • Structuremap.dll (not part of the Sitecore Solr Support Package)

Step 5: Check that it works!

  • Re-index it all
    1. Go to the Control Panel
    2. Choose Indexing Manager
    3. Select All
    4. Click “Start”

Summary – and downloads

The fast way to get Solr 6 running with Sitecore 8.2. is shown in this post. The fast way:

  • Download zzzsolrindexes for Sitecore 8.2 – unzip and place that under App_Config\Include
  • Download cores_conf for Solr 6.2 – unzip and place under your Solr 6 installation – under \solr-6.2.1\server\solr
  • Download the support Solr package – select your favorite IoC and select the DLL and config that fits with your choice.
  • Restart your Solr and go rebuild your Sitecore indexes.
  • You are now running on Solr instead of Lucene.
How to use Solr with Sitecore 8.2 with Solr 6 – the easy way
Tagged on:             

6 thoughts on “How to use Solr with Sitecore 8.2 with Solr 6 – the easy way

  • November 10, 2016 at 4:07 pm
    Permalink

    Do we really have to use Solr support packages. I was able to query Solr without it and does it use the ContentSearch API?

    I saw you mentioning using SolrNet but i thought CententSearch was using SolrNet underneath.

    what do i gain using one vs another.

    Thank you

    Reply
  • December 17, 2016 at 9:50 am
    Permalink

    Hi Roland,
    I am trying to set up Solr 6.1 with sitecore 8.2. i have followed all the steps mentioned in this post.however after setup i am getting “Connection error to search provider [Solr]: Unable to connect to [http:localhost:8934/solr],Core:[sitecore_analytics_index]” error while accessing sitecore instance. upon checking sitecore logs i can see “The remote server returned an error: (401) Unauthorized” as a nested exception.

    Reply
    • January 16, 2017 at 10:59 am
      Permalink

      Hi Kumkar,

      A couple of checks. So you are 100% sure that your Solr runs on port 8934? I’m asking since this is not default from a standard setup, but absolutely fine. Secondly: What does your Solr tells you in the Solr log (Go to solr admin). Last: Check also that all your cores are up running.

      Let me know
      /Roland

      Reply
      • March 5, 2017 at 2:38 pm
        Permalink

        Hi Roland,
        Thanks for your response. My Solr is up and running on mentioned port. i can successfully query core from solr admin dashboard. but when i was trying to access solr using sitecore it was giving an 401 unathorized error.
        However above issue is resolved now by changing “solrHttpWebRequestFactory” setting present in solr.defaultindexconfiguration.config to “BasicAuthHttpWebRequestFactory” with username and password.

        Reply
  • September 26, 2017 at 6:17 am
    Permalink

    Hi Kumar,

    I just seen your question about solar. Did you check your connection to Solr from Sitecore ? is it configured correctly?. This is done by opening the configuration file named Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config and verify that the setting ContentSearch.Solr.ServiceBaseAddress is configured to point to your Solr server.

    Thanks
    Sree

    Reply

Leave a Reply

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