1

I am newbie to Solr Index and its custom field mapping in sitecore along with its configuration.

I have googled so much but I am got completely confused and unable to start from basic.

Please give me on guide to get started?

I want to understand about the configuration in sitecore to include few fields of template.

And how to map solr custom index fields with template fields name?

Thankyou for any guidance.

5 Answers 5

4

You can perform below steps:

Create Cores in Solr

  1. Go to the SOLR folder (like D:\SOLR\solr-7.7.2\solr-7.7.2)

enter image description here

  1. Go to solr folder under server folder (D:\SOLR\solr-7.7.2\solr-7.7.2\server\solr)
  2. Copy & Paste the Web index folder (in my case: Sitecore92Testing_web_index) & rename it as a custom index.

enter image description here

  1. Open the folder and edit the core.properties file. Update the name from web index to custom index.

enter image description here

  1. Go to the solr, the new custom index core will be reflected in the SOLR instance.

Sitecore Patch file for custom index

  1. Go to your Sitecore instance’s Content Search config folder (in my case: C:\inetpub\wwwroot\SitecoreDemo.dev.local\App_Config\Sitecore\ContentSearch).

  2. Go to your Sitecore instance’s Content Search config folder (in my case: C:\inetpub\wwwroot\SitecoreDemo.dev.local\App_Config\Sitecore\ContentSearch).

enter image description here

  1. Open the file in Notepad++, and edit XML
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/">
  <sitecore role:require="Standalone or ContentDelivery or ContentManagement" search:require="solr">
    <contentSearch>
      <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
        <indexes hint="list:AddIndex">
          <index id="sitecore_custom_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
            <param desc="name">$(id)</param>
            <param desc="core">Sitecore92Testing_custom_index</param>
            <param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
            <configuration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration">
                  <documentOptions type="Sitecore.ContentSearch.SolrProvider.SolrDocumentBuilderOptions, Sitecore.ContentSearch.SolrProvider">
                      <indexAllFields>false</indexAllFields>                  
                      <include hint="list:AddIncludedField">
                          <CustomFieldID>GUID</CustomFieldID>                         
                      </include>                    
                      <include hint="list:AddIncludedTemplate">
                          <CustomTemplate>GUID</CustomTemplate>
                      </include>
                  </documentOptions>
              </configuration>           
            <strategies hint="list:AddStrategy">
                <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/manual" role:require="(ContentManagement and !Indexing) or (ContentDelivery and !Indexing)" />
                <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsyncSingleInstance" role:require="Standalone or (ContentManagement and Indexing) or (ContentDelivery and Indexing)" />
            </strategies>
            <locations hint="list:AddCrawler">
              <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
                <Database>web</Database>
                <Root>/sitecore/content/home</Root>
              </crawler>
            </locations>
            <enableItemLanguageFallback>false</enableItemLanguageFallback>
            <enableFieldLanguageFallback>false</enableFieldLanguageFallback>
          </index>
        </indexes>
      </configuration>
    </contentSearch>
  </sitecore>
</configuration>

You can replace <CustomFieldID>GUID</CustomFieldID> with your custom fields and it could be multiple and the same for <CustomTemplate>GUID</CustomTemplate>

0

You need to follow these steps for the custom one.

  1. Find your Solr index folder for the sitecore_master_index. Example C:\solr\solr-6.6.2\server\solr\sitecore_master_index
  2. Copy this whole folder (into the same parent folder) and call it for example sitecore_master_products_index
  3. Inside the sitecore_master_products_index folder, open up the core.properties file and change the name property to read sitecore_master_products_index
  4. Restart Solr (I use the solr stop and solr start commands – see below)
  5. Now, go to https://solr:8983/solr/#/ and check out your cores – you will have a new one!

And here is the custom configuration file.

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/">
  <sitecore role:require="Standalone or ContentManagement" search:require="solr">
    <contentSearch>
      <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
        <indexes hint="list:AddIndex">
          <index id="sitecore_master_products_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
            <param desc="name">$(id)</param>
            <param desc="core">$(id)</param>
            <param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
              <configuration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration">
                  <documentOptions type="Sitecore.ContentSearch.SolrProvider.SolrDocumentBuilderOptions, Sitecore.ContentSearch.SolrProvider">
                      <indexAllFields>false</indexAllFields>

                      <!-- Included fields -->
                      <include hint="list:AddIncludedField">
                          <ProductName>{E676F36E-B0E0-4BE5-998A-329A8F9055FD}</ProductName>
                          <LongDescription>{8A978A2E-0E7A-4415-9163-2F4ECF85A3AB}</LongDescription>
                      </include>

                      <!-- Included templates -->
                      <include hint="list:AddIncludedTemplate">
                          <Product>{665DC431-673A-4D63-B9A6-00EB148E693C}</Product>
                      </include>

                  </documentOptions>
              </configuration>
            <strategies hint="list:AddStrategy">
              <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/syncMaster" />
            </strategies>
            <locations hint="list:AddCrawler">
              <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
                <Database>master</Database>
                <Root>/sitecore</Root>
              </crawler>
            </locations>
            <enableItemLanguageFallback>false</enableItemLanguageFallback>
            <enableFieldLanguageFallback>false</enableFieldLanguageFallback>
          </index>
        </indexes>
      </configuration>
    </contentSearch>
  </sitecore>
</configuration>

Refer to this for more details.

https://chrisperks.com/custom_solr_index/

Hope this helps.

0

If you have multiple developers in your team I suggest to use Powershell to create indexes create-solr-core.ps1 because is faster to create indexes using scripts :

param(
    [string]$Name,
    [string]$Prefix = "sitecore",
    [string]$SolrRoot = "C:\solr\yoursolrversion",
    [string]$BaseCoreId = "master"
)

$baseCoreName = "$($Prefix)_$($BaseCoreId)_index"
$solrIndexesDir = "$($SolrRoot)\server\solr"


$newCoreName = "$($Prefix)_$($Name)_index"

# Prepare directory for creation Solr Core
$newCoreConfDir = "$($solrIndexesDir)\$($newCoreName)\conf"
if ( -not $(Test-Path $newCoreConfDir)) {
    New-Item -Path $newCoreConfDir -Type Directory
}
Copy-Item -Path "$($solrIndexesDir)\$($baseCoreName)\conf\*" -Destination $newCoreConfDir -Recurse
Push-Location "$($SolrRoot)\bin"
.\solr create -c $newCoreName
Pop-Location

You can create indexes using this command :

.\create-solr-core.ps1 -Name custom

You need to have your custom index configuration file like on Sumit answer :

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/">
  <sitecore role:require="Standalone or ContentManagement" search:require="solr">
    <contentSearch>
      <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
        <indexes hint="list:AddIndex">
          <index id="sitecore_custom_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
            <param desc="name">$(id)</param>
            <param desc="core">$(id)</param>
            <param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
              <configuration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration">
                  <documentOptions type="Sitecore.ContentSearch.SolrProvider.SolrDocumentBuilderOptions, Sitecore.ContentSearch.SolrProvider">
                      <indexAllFields>false</indexAllFields>

                      <!-- Included fields -->
                      <include hint="list:AddIncludedField">
                          <ProductName>{E676F36E-B0E0-4BE5-998A-329A8F9055FD}</ProductName>
                          <LongDescription>{8A978A2E-0E7A-4415-9163-2F4ECF85A3AB}</LongDescription>
                      </include>

                      <!-- Included templates -->
                      <include hint="list:AddIncludedTemplate">
                          <Product>{665DC431-673A-4D63-B9A6-00EB148E693C}</Product>
                      </include>

                  </documentOptions>
              </configuration>
            <strategies hint="list:AddStrategy">
              <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/syncMaster" />
            </strategies>
            <locations hint="list:AddCrawler">
              <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
                <Database>master</Database>
                <Root>/sitecore</Root>
              </crawler>
            </locations>
            <enableItemLanguageFallback>false</enableItemLanguageFallback>
            <enableFieldLanguageFallback>false</enableFieldLanguageFallback>
          </index>
        </indexes>
      </configuration>
    </contentSearch>
  </sitecore>
</configuration>
0

Follow the below steps to create a custom Solr index.

  1. Go to the local SOLR folder.
  2. Copy & Paste the Web index folder & rename it as a custom index.
  3. Open the folder and edit the core.properties file. Update the name from web index to custom index.
  4. To reflect these changes in our SOLR search, you must restart your Solr services.
  5. Open Run (Win + R), type services.msc & click OK.
  6. Go to SOLR service and restart it.
  7. Once the restart is successful, the new custom index core will get reflected in our SOLR instance.
  8. Go to your Sitecore instance’s Content Search config folder (in my case: C:\inetpub\wwwroot\SitecoreDemo.dev.local\App_Config\Sitecore\ContentSearch).
  9. Copy & Paste the Sitecore.ContentSearch.Solr.Index.Web.config file and rename it as Sitecore.ContentSearch.Solr.Index.Custom.config.
  10. Open the file in Notepad++, and edit the below highlighted values enter image description here
  11. Save the file and recycle the app-pool of your Sitecore instance.
  12. Now, we need to rebuild it once so that only specific items will be indexed.

Reference:How to create a custom SOLR index

Hope it helps!

0

You will need to create custom index configuration for the new solr core you add. This index configuration contains the path where the indexing crawler will start indexing content as well as indexing strategies.

<?xml version="1.0" encoding="utf-8"?>

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/">
  <sitecore role:require="Standalone or ContentDelivery or ContentManagement" search:require="solr">
    <contentSearch>
      <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
        <indexes hint="list:AddIndex">
      <index id="{{custom_index_name}}" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
        <param desc="name">$(id)</param>
        <param desc="core">{{custom_index_name}}</param>
        <param desc="propertyStore" ref="contentSearch/indexConfigurations/databasePropertyStore" param1="$(id)" />
        <configuration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration">
          <documentOptions type="Sitecore.ContentSearch.SolrProvider.SolrDocumentBuilderOptions, Sitecore.ContentSearch.SolrProvider">
             <indexAllFields>false</indexAllFields>
             <!-- Included fields -->
             <include hint="list:AddIncludedField">
               <Title>{E676F36E-B0E0-4BE5-998A-329A8F9055FD}</Title>
               <Description>{8A978A2E-0E7A-4415-9163-2F4ECF85A3AB}</Description>
              </include>
              <!-- Included templates -->
              <include hint="list:AddIncludedTemplate">
                 <Product>{665DC431-673A-4D63-B9A6-00EB148E693C}</Product>
              </include>
           </documentOptions>
        </configuration>
        <strategies hint="list:AddStrategy" role:require="Standalone or ContentManagement">
          <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/onPublishEndAsync" />
        </strategies>
        <strategies hint="list:AddStrategy" role:require="ContentDelivery">
          <strategy ref="contentSearch/indexConfigurations/indexUpdateStrategies/manual" />
        </strategies>
        <locations hint="list:AddCrawler" role:require="Standalone or ContentManagement">
          <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch" >
            <Database>web</Database>
            <Root>/sitecore/content/{{sitename}}</Root>
          </crawler>
        </locations>
        <enableItemLanguageFallback>true</enableItemLanguageFallback>
        <enableFieldLanguageFallback>true</enableFieldLanguageFallback>
      </index>
    </indexes>
  </configuration>
</contentSearch>

In the above configuration, you will need to replace following placeholders:

  1. custom_index_name , will be the index name
  2. site_name, will contain the site start path

Moreover in the above configuration, since we are setting indexAllFields flag as false, therefore we need to configure the field ids or template ids to be indexed and stored on SOLR.

You can find more details on the indexing strategy and how the solr field name gets resolved on the below links:

https://doc.sitecore.com/xp/en/developers/101/platform-administration-and-architecture/index-update-strategies.html

https://doc.sitecore.com/xp/en/developers/101/platform-administration-and-architecture/using-solr-field-name-resolution.html

Hope this helps!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.