ドキュメントをSolrに送信する際にSystem.OutOfMemoryExceptionエラーが発生する


解説

以下のエラーがログに出力され、検索インデックスの再構築またはリフレッシュが失敗する可能性があります。

Exception: System.OutOfMemoryException
Message: Exception of type 'System.OutOfMemoryException' was thrown.
Source: mscorlib
   at System.Text.StringBuilder.ToString()
   at System.Xml.Linq.XNode.GetXmlString(SaveOptions o)
   at SolrNet.Commands.AddCommand`1.ConvertToXml()
   at SolrNet.Commands.AddCommand`1.Execute(ISolrConnection connection)
   at SolrNet.Impl.LowLevelSolrServer.SendAndParseHeader(ISolrCommand cmd)
   at Sitecore.ContentSearch.SolrProvider.SolrBatchUpdateContext.Commit()
   at Sitecore.ContentSearch.SolrProvider.SolrSearchIndex.PerformRebuild(Boolean resetIndex, Boolean optimizeOnComplete, IndexingOptions indexingOptions, CancellationToken cancellationToken)
   at Sitecore.ContentSearch.SolrProvider.SolrSearchIndex.Rebuild(Boolean resetIndex, Boolean optimizeOnComplete)

解決策

オプション1

この問題を予防するには、\App_Config\Include\zzzフォルダーに構成パッチ ファイルを作成して、ContentSearch.Update.BatchSize設定の値を減少させます。
例:

<?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 search:require="solr">
    <settings>
      <setting name="ContentSearch.Update.BatchSize" value="25" />
    </settings>
  </sitecore>
</configuration>

註: この設定変更により、インデックスの更新・再構築速度が遅くなったり、Solrサーバー上でのリソースの消費量が増大する場合があります。

オプション2

このエラーは、必ずしもアプリケーションのメモリが不足していることを示すものではありません。この問題は、大量のコンテンツを含む複数のドキュメントのような大きなオブジェクトの割り当てを妨げる、大きなオブジェクト ヒープ(LOH)の断片化によっても発生する可能性があります。

大量のコンテンツを有しているフィールドを特定するには、Sitecore Crawlingログを使用します。

  1. このページに記載されている方法に従って、DEBUGロギング レベルと詳細なロギングをを有効化します(これらを有効化すると、ログ ファイルのサイズが著しく増加する場合があることにご注意ください)。
  2. 検索インデックスを再構築し、ログを確認します。

大量のコンテンツを含むフィールドをインデックス作成から除外するには、\App_Config\Include\zzzフォルダーに構成パッチ ファイルを作成して、除外フィールドのリストを拡張します。

<?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 search:require="solr">
    <contentSearch>
      <indexConfigurations>
        <defaultSolrIndexConfiguration>
          <documentOptions>
            <exclude hint="list:AddExcludedField">
              <FieldName>{フィールドのID}</FieldName>
            </exclude>
          </documentOptions>
        </defaultSolrIndexConfiguration>
      </indexConfigurations>
    </contentSearch>
  </sitecore>
</configuration>