7

I am moving indexes from Lucene to Solr. Almost everything is working again, except a few custom indexes that have their own index configuration and had some field added to the fieldMap. Other custom indexes are working. The error I get when starting the site is:

[KeyNotFoundException: The given key was not present in the dictionary.] System.Collections.Generic.Dictionary`2.get_Item(TKey key) +13763335
Sitecore.ContentSearch.SolrProvider.SolrFieldMap.AddFieldByFieldName(XmlNode configNode) +618

[TargetInvocationException: Exception has been thrown by the target of an invocation.] X.X.Web.Global.Application_Error(Object sender, EventArgs e) in ...\Global.asax.cs:76 System.Web.HttpApplication.RaiseOnError() +211

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +544
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +186
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +402
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +343

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +579
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +112 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +716

The index config now:

<indexConfigurations>
    <CustomIndexConfiguration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration">
      <fieldMap type="Sitecore.ContentSearch.SolrProvider.SolrFieldMap, Sitecore.ContentSearch.SolrProvider">
        <fieldNames hint="raw:AddFieldByFieldName">
          <field fieldName="text" returnType="string" />
          <field fieldName="webshops" returnType="string" />
          <field fieldName="attributes" returnType="string" />
        </fieldNames>
      </fieldMap>
      <documentOptions type="Sitecore.ContentSearch.SolrProvider.SolrDocumentBuilderOptions, Sitecore.ContentSearch.SolrProvider">
        ...
      </documentOptions>
    </CustomIndexConfiguration>
 </indexConfigurations>

My old Lucene config had a fieldMap like this:

<fieldNames hint="raw:AddFieldByFieldName">
    <field fieldName="text" storageType="YES" indexType="UNTOKENIZED" vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider"/>
    <field fieldName="webshops" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider"/>
    <field fieldName="attributes" storageType="YES" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
</fieldNames>

I am definitely missing something (otherwise I wouldn't get an error). Buy what?

Using Sitecore 8.1-upd3, Solr 4.10.3, Autofac 4.1, ...

  • what version of sitecore and solr are you using? – sc.kp Oct 13 '16 at 17:07
  • Your code looks correct. How do you use that new Index? If you are trying to replace standard Sitecore indexes you need to keep all default fields. – Dmitry Harnitski Oct 13 '16 at 17:18
  • Could you attach the full stack trace? – Dmytro Shevchenko Oct 13 '16 at 17:47
  • Added version info and full stack trace – Gatogordo Oct 13 '16 at 18:16
  • I'm not trying to replace the standard indexes. I have a few extra custom indexes next to the standard Sitecore ones. The application starts, even with some custom indexes, as long as I don't include the ones with a fieldMap in the configuration. – Gatogordo Oct 13 '16 at 18:18
12

I think you may be missing type matches within your field map. Try adding this section before your <fieldNames> section

<typeMatches hint="raw:AddTypeMatch">
    <typeMatch typeName="string" type="System.String" fieldNameFormat="{0}_s" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
</typeMatches>

I grabbed that from the example Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config file

Alternatively, you can try referencing the default field map like this:

<fieldMap ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/fieldMap"> 
  • Your alternative (adding the "ref" to the fieldMap element) did the trick! – Gatogordo Oct 14 '16 at 7:36
  • 1
    This worked for me as well in working with SOLR for the first time. Elusive error. Thanks Mark! – Toby Gutierrez Aug 4 '17 at 20:13

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.