Sitecore Custom Language and SOLR Indexing Error
Recently we have added the Korean language to our multilingual Sitecore website. As we know Sitecore automatically creates dynamic fields in the SOLR schema. But while publishing we found the following issue in our logs:
<str name="msg"> | |
ERROR: [doc=sitecore://web/{2e189210-124d-4711-8e11-39f8d4ef8b48}?lang=ko-kr&ver=1&ndx=sitecore_web_index] | |
unknown field '******_*****_***_t_ko' | |
</str> |
9360 03:42:21 INFO Job started: Publish | |
8920 03:42:21 INFO Job started: Publish to 'web' | |
ManagedPoolThread #11 03:42:24 ERROR Exception | |
Exception: System.Reflection.TargetInvocationException | |
Message: Exception has been thrown by the target of an invocation. | |
Source: mscorlib | |
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) | |
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) | |
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) | |
at Sitecore.Reflection.ReflectionUtil.InvokeMethod(MethodInfo method, Object[] parameters, Object obj) | |
at Sitecore.Jobs.JobRunner.RunMethod(JobArgs args) | |
at (Object , Object ) | |
at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) | |
at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists) | |
at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) | |
at Sitecore.Jobs.DefaultJob.DoExecute() | |
at Sitecore.Abstractions.BaseJob.ThreadEntry(Object state) | |
Nested Exception | |
Exception: SolrNet.Exceptions.SolrConnectionException | |
Message: <?xml version="1.0" encoding="UTF-8"?> | |
<response> | |
<lst name="responseHeader"> | |
<int name="rf">3</int> | |
<int name="status">400</int> | |
<int name="QTime">106</int> | |
</lst> | |
<lst name="error"> | |
<lst name="metadata"> | |
<str name="error-class">org.apache.solr.common.SolrException</str> | |
<str name="root-error-class">org.apache.solr.common.SolrException</str> | |
</lst> | |
<str name="msg">ERROR: [doc=sitecore://web/{2e189210-124d-4711-8e11-39f8d4ef8b48}?lang=ko-kr&ver=1&ndx=sitecore_web_index] unknown field '******_*****_***_t_ko'</str> | |
<int name="code">400</int> | |
</lst> | |
</response> | |
Source: SolrNet | |
at SolrNet.Impl.SolrConnection.PostStream(String relativeUrl, String contentType, Stream content, IEnumerable`1 parameters) | |
at SolrNet.Impl.SolrConnection.Post(String relativeUrl, String s) | |
at SolrNet.Impl.LowLevelSolrServer.SendAndParseHeader(ISolrCommand cmd) | |
at Sitecore.ContentSearch.SolrProvider.SolrFullBatchUpdateContext.Flush() | |
at Sitecore.ContentSearch.SolrProvider.SolrFullBatchUpdateContext.Commit() | |
at Sitecore.ContentSearch.AbstractSearchIndex.PerformUpdate(IEnumerable`1 indexableInfo, IndexingOptions indexingOptions) | |
Nested Exception | |
Exception: System.Net.WebException | |
Message: The remote server returned an error: (400) Bad Request. | |
Source: System | |
at System.Net.HttpWebRequest.GetResponse() | |
at HttpWebAdapters.Adapters.HttpWebRequestAdapter.GetResponse() | |
at SolrNet.Impl.SolrConnection.GetResponse(IHttpWebRequest request) | |
at SolrNet.Impl.SolrConnection.PostStream(String relativeUrl, String contentType, Stream content, IEnumerable`1 parameters) | |
8920 03:42:27 INFO Job ended: Publish to 'web' (units processed: 110) | |
9360 03:42:27 INFO Job ended: Publish (units processed: ) |
Solution:
The error is in sitecore_web_index and it seems we are missing a dynamic field for the Korean language.
-
To solve this issue, we need to add the dynamic field in the SOLR schema
file:
<dynamicField name="*_t_ko" type=" text_general" indexed="true" stored="true" />
- Restart the SOLR
But take care that whenever you populate the managed schema from Sitecore, it will overwrite your managed schema, and you will lose all the changes.
Another approach is to customize the SOLR schema using backend code.
Step 1: Create a custom class and add the following logic:
public class CustomLanguageIndexHelper : SchemaPopulateHelper | |
{ | |
public CustomLanguageIndexHelper(SolrSchema solrSchema) : base(solrSchema) | |
{ | |
} | |
public override IEnumerable<XElement> GetAllFields() | |
{ | |
return base.GetAllFields().Union(GetAddCustomFields()); | |
} | |
public override IEnumerable<XElement> GetAllFieldTypes() | |
{ | |
return base.GetAllFieldTypes().Union(GetAddCustomFieldTypes()); | |
} | |
private IEnumerable<XElement> GetAddCustomFields() | |
{ | |
yield return CreateField("*_t_ko", | |
"text_general", | |
isDynamic: true, | |
required: false, | |
indexed: true, | |
stored: true, | |
multiValued: false, | |
omitNorms: false, | |
termOffsets: false, | |
termPositions: false, | |
termVectors: false); | |
} | |
private IEnumerable<XElement> GetAddCustomFieldTypes() | |
{ | |
yield return CreateFieldType("randomType", "solr.RandomSortField", | |
new Dictionary<string, string> | |
{ | |
{ "indexed", "true" } | |
}); | |
} | |
} |
Step 2: Create one more class that inherits from IPopulateHelperFactory implement the GetPopulateHelper method, and return your custom class from Step 1.
public class CustomLanguagePopulateHelperFactory : IPopulateHelperFactory | |
{ | |
public ISchemaPopulateHelper GetPopulateHelper(SolrSchema solrSchema) | |
{ | |
return new CustomLanguageIndexHelper(solrSchema); | |
} | |
} |
Step 3: Create a configuration file and patch your code in contentSearch.PopulateSolrSchema pipeline:
<?xml version="1.0" encoding="utf-8" ?> | |
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> | |
<sitecore> | |
<pipelines> | |
<contentSearch.PopulateSolrSchema> | |
<processor type="Sitecore.ContentSearch.SolrProvider.Pipelines.PopulateSolrSchema.PopulateFields, | |
Sitecore.ContentSearch.SolrProvider"> | |
<param type="WebsiteNameSpace.ProjectName.CustomLanguagePopulateHelperFactory, WebsiteNameSpace.ProjectName" | |
patch:instead="*[@type='Sitecore.ContentSearch.SolrProvider.Factories.DefaultPopulateHelperFactory']"/> | |
</processor> | |
</contentSearch.PopulateSolrSchema> | |
</pipelines> | |
</sitecore> | |
</configuration> |
Reference: https://support.sitecore.com/kb?id=kb_article_view&sysparm_article=KB0848433
Happy Sitecoreing 😊
Comments
Post a Comment