3

I am converting my custom index fields from Sitecore 8.1.

Previously, I would declare them like this:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <contentSearch>
      <indexConfigurations>
        <myCustomIndexConfiguration type="Sitecore.ContentSearch.SolrProvider.SolrIndexConfiguration, Sitecore.ContentSearch.SolrProvider">
          <documentOptions>
            <fields hint="raw:AddComputedIndexField">
              <field fieldName="parsed_content_keywords" returnType="customStringCol" storageType="yes" multiValued="true">
                MyProject.Search.ComputedFields.ParsedContentKeywords, MyProject.Search
              </field>
            </fields>
          </documentOptions>
        </myCustomIndexConfiguration>
      </indexConfigurations>
    </contentSearch>
  </sitecore>
</configuration>

And customStringCol is declared like this:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <contentSearch>
      <indexConfigurations>
        <myCustomIndexConfiguration type="Sitecore.ContentSearch.SolrProvider.SolrIndexConfiguration, Sitecore.ContentSearch.SolrProvider">
          <fieldMap type="Sitecore.ContentSearch.SolrProvider.SolrFieldMap, Sitecore.ContentSearch.SolrProvider">
            <typeMatches hint="raw:AddTypeMatch">
              <typeMatch typeName="customStringCol"     type="System.Collections.Generic.List`1[System.String]" fieldNameFormat="{0}_csm" multiValued="true" indexed="true" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider"/>
            </typeMatches>
          </fieldMap>
        </myCustomIndexConfiguration>
      </indexConfigurations>
    </contentSearch>
  </sitecore>
</configuration>

In Sitecore 8.1 and Solr 4.10x, this configuration results in the index working correctly. In Sitecore 9.1 and Solr 7.2.1, this results in the Solr log outputting the following SolrException:

ERROR: [doc=sitecore://web/{c6ccedd5-28a9-4707-8717-7482a48b538f}?lang=en&ver=1&ndx=sitecore_web_index] unknown field 'parsed_content_keywords_csm'

Question

How do I create a custom index in Sitecore 9.1 and Solr 7.2.1? Could someone share a sample config similar to the one I posted above that works in this scenario?

  • 4
    It doesn't seem like you are creating an index as much as just adding fields. See Habitat for an example. github.com/Sitecore/Habitat/blob/master/src/Foundation/Indexing/… – Chris Auer Mar 21 at 21:58
  • 2
    have you populated the "Solr Managed Schema"? this gets me every time with errors like this – Gravypower Mar 21 at 23:24
  • Chris Auer yes, this is what I'm trying to do - adding custom fields. And it looks like the way I'm configuring it is the same as in Habitat's example. Do I need to do anything else on the core configuration? – Emanuele Ciriachi Mar 22 at 9:55
  • I changed the title - I'm indeed trying to create custom fields. – Emanuele Ciriachi Mar 22 at 12:37
0

Fix SolrException

You could try using stringCollection type, which is already defined in Sitecore Solr-configuration:

<typeMatch type="System.Collections.Generic.List`1[System.String]" typeName="stringCollection" fieldNameFormat="{0}_sm" multiValued="true" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider"/>

So, just change your field:

<field fieldName="parsed_content_keywords" returnType="stringCollection" storageType="YES">
    MyProject.Search.ComputedFields.ParsedContentKeywords, MyProject.Search
</field>

To create custom index

1. Create core in Solr:

You could use this script, but set custom values to BASE_CORE_NAME - already existing Solr core, which will be copied for a new one; SOLR_ROOT - path to solr.

echo off
SET BASE_CORE_NAME=[sitecore_web_index]
SET core_name=%1
SET SOLR_ROOT=c:\Program Files\solr-6.6.2
SET SOLR_INDEXES_DIR="%SOLR_ROOT%\server\solr\"

set NEW_INDEX_CONF_DIR=%SOLR_INDEXES_DIR%\%core_name%\conf
set BASE_INDEX_CONF_DIR=%SOLR_INDEXES_DIR%\%BASE_CORE_NAME%\conf
call mkdir %NEW_INDEX_CONF_DIR%
call xcopy %BASE_INDEX_CONF_DIR% %NEW_INDEX_CONF_DIR% /s

call "%SOLR_ROOT%\bin\solr" create -c %core_name%

And execute:

create-core.cmd [core_name]

2. Create sitecore index

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <contentSearch>
            <configuration type="Sitecore.ContentSearch.ContentSearchConfiguration, Sitecore.ContentSearch">
                <indexes>
                    <index id="[YOUR_INDEX_NAME]"
                           type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
                        <param desc="name">$(id)</param>
                        <param desc="core">[SOLR_CORE_NAME]</param>
                        <param ref="contentSearch/indexConfigurations/databasePropertyStore" desc="propertyStore"
                               param1="$(id)" />
                        <configuration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration" />
                        <locations hint="list:AddCrawler">
                           <!-- ADD YOUR CRAWLERS HERE -->
                        </locations>
                        <enableItemLanguageFallback>false</enableItemLanguageFallback>
                        <enableFieldLanguageFallback>false</enableFieldLanguageFallback>
                    </index>
                </indexes>
            </configuration>
        </contentSearch>
    </sitecore>

</configuration>

3. Sitecore post-create steps

  1. Populate "Solr Managed Schema"
  2. Rebuild index

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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