0

Using Sitecore 9.1 I'm trying to add some custom index fields and my config patch is throwing the below error when I add AddFieldByField name elements:

[ConfigurationException: Unable to process 'AddFieldByFieldName' config section.]
Sitecore.ContentSearch.SolrProvider.SolrFieldMap.AddFieldByFieldName(XmlNode configNode) +909

[TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +128
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +142 Sitecore.Configuration.DefaultFactory.AssignProperties(Object obj, Object[] properties) +859
Sitecore.Configuration.DefaultFactory.AssignProperties(XmlNode configNode, String[] parameters, Object obj, Boolean assert, Boolean deferred, IFactoryHelper helper) +620
Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper) +320
Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert) +72
Sitecore.Configuration.DefaultFactory.GetInnerObject(XmlNode paramNode, String[] parameters, Boolean assert) +109
Sitecore.Configuration.DefaultFactory.AssignProperties(XmlNode configNode, String[] parameters, Object obj, Boolean assert, Boolean deferred, IFactoryHelper helper) +527
Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper) +320
Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert) +72
Sitecore.Configuration.DefaultFactory.CreateObject(String configPath, String[] parameters, Boolean assert) +703
Sitecore.Configuration.DefaultFactory.CreateFromReference(XmlNode configNode, String[] parameters, Boolean assert) +170
Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper) +116
Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert) +72
Sitecore.Configuration.DefaultFactory.GetInnerObject(XmlNode paramNode, String[] parameters, Boolean assert) +109
Sitecore.Configuration.DefaultFactory.AssignProperties(XmlNode configNode, String[] parameters, Object obj, Boolean assert, Boolean deferred, IFactoryHelper helper) +527
Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper) +320
Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert) +72
Sitecore.Configuration.DefaultFactory.GetInnerObject(XmlNode paramNode, String[] parameters, Boolean assert) +941
Sitecore.Configuration.DefaultFactory.AssignProperties(XmlNode configNode, String[] parameters, Object obj, Boolean assert, Boolean deferred, IFactoryHelper helper) +527
Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper) +320
Sitecore.Configuration.DefaultFactory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert) +72
Sitecore.Configuration.DefaultFactory.CreateObject(String configPath, String[] parameters, Boolean assert) +703
Sitecore.ContentSearch.ContentSearchManager.get_SearchConfiguration() +311 Sitecore.ContentSearch.SolrProvider.SolrContentSearchManager.Initialize() +21 (Object , Object ) +9 Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +484
Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists) +236 Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +22
Sitecore.Nexus.Web.HttpModule.Application_Start() +215
Sitecore.Nexus.Web.HttpModule.Init(HttpApplication app) +1184
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +581
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +168
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +277
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +369

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

If I comment out those 3 elements then site loads fine. My patch is:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <contentSearch>
      <indexConfigurations>
        <defaultEventsIndexConfiguration type="Sitecore.ContentSearch.SolrProvider.SolrIndexConfiguration, Sitecore.ContentSearch.SolrProvider">
          <documentOptions type="Sitecore.ContentSearch.SolrProvider.SolrDocumentBuilderOptions, Sitecore.ContentSearch.SolrProvider">
            <indexAllFields>false</indexAllFields>
            <include hint="list:AddIncludedTemplate">
              <EventDetails>{5C873C37-68F7-4B90-BE99-C60083AE459F}</EventDetails>

            </include>
            <include hint="list:AddIncludedField">

              <contentheading>{119570A4-0810-4D81-88CD-E64E4D4DD0D6}</contentheading>
              <contentintro>{239319A2-488E-4CA9-B0C9-99876FA8B74F}</contentintro>
              <startdate>{83D79FDC-7D0C-412F-9F9F-F007C17A52C0}</startdate>

            </include>
            <fields hint="raw:AddComputedIndexField">
              <!--<field fieldName="urllink">TAC.Utils.Search.UrlComputedField, TAC.Utils</field>-->
            </fields>
          </documentOptions>
          <initializeOnAdd>false</initializeOnAdd>
          <fieldMap type="Sitecore.ContentSearch.SolrProvider.SolrFieldMap, Sitecore.ContentSearch.SolrProvider">
            <typeMatches hint="raw:AddTypeMatch">
              <typeMatch typeName="text" type="System.String" fieldNameFormat="{0}_t" cultureFormat="_{1}" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
              <typeMatch typeName="datetime" type="System.DateTime" fieldNameFormat="{0}_tdt" format="yyyy-MM-dd'T'HH:mm:ss.FFF'Z'" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
              <typeMatch typeName="string" type="System.String" fieldNameFormat="{0}_s" settingType="Sitecore.ContentSearch.SolrProvider.SolrSearchFieldConfiguration, Sitecore.ContentSearch.SolrProvider" />
            </typeMatches>
            <fieldNames hint="raw:AddFieldByFieldName">
              <field fieldName="contentheading" returntype="text"/>
              <field fieldName="contentintro" returntype="text"/>
              <field fieldName="startdate" returntype="datetime" format="yyyy-MM-dd'T'HH:mm:ss'Z'"/>

            </fieldNames>

          </fieldMap>
          <!-- **** Inherited default configuration **** -->
          <fieldReaders ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/fieldReaders" />
          <indexFieldStorageValueFormatter ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/indexFieldStorageValueFormatter" />
          <indexDocumentPropertyMapper ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/indexDocumentPropertyMapper" />
          <documentBuilderType ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration/documentBuilderType" />

        </defaultEventsIndexConfiguration>
      </indexConfigurations>
    </contentSearch>
  </sitecore>
</configuration>

Not sure what I'm missing as the fieldMap section contains the types of my fields (as suggested by other posts).

1 Answer 1

3

Sitecore configs are case sensitive.

Your config contains returntype with lowercase t character.

It should be returnType with capitacl case T.

<fieldNames hint="raw:AddFieldByFieldName">
  <field fieldName="contentheading" returnType="text"/>
  <field fieldName="contentintro" returnType="text"/>
  <field fieldName="startdate" returnType="datetime" format="yyyy-MM-dd'T'HH:mm:ss'Z'"/>
</fieldNames>
4
  • Nice one - thanks :)
    – Jen
    Commented Jul 23, 2019 at 7:15
  • @marek is there any documentation you know of that defines what you can put in <fieldNames hint="raw:AddFieldByFieldName"> section? I'm at a total loss. For example, here there is a format="xxx" but what other attributes or sub-elements are supported for SOLR config? How do you know format="xx" is a supported attribute and not just ignored?
    – theyetiman
    Commented Oct 10, 2019 at 16:15
  • Just check what Sitecore uses in its own configs
    – Marek Musielak
    Commented Oct 10, 2019 at 17:34
  • When I was messing with this. I noticed that the fieldName is not a recognized field. It throws an error "The given key was not present in the dictionary". I dotpeeked at the implementation, and the keys AddFieldByFieldName is looking for are "fieldTypeName","returnType", and "boost" The fieldTypeName and returnType are required or you'll get an "Unable to process 'AddFieldByFieldName' config section." error. Maybe changed since this post.
    – Anthony
    Commented Mar 12 at 0:46

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.