Azure Search .net SDKを使用すると、ドキュメントのインデックスを作成しようとすると、例外IndexBatchException
が発生することがあります。Azure検索.net SDK- "FindFailedActionsToRetry"の使い方は?
try
{
var batch = IndexBatch.Upload(documents);
indexClient.Documents.Index(batch);
}
catch (IndexBatchException e)
{
// Sometimes when your Search service is under load, indexing will fail for some of the documents in
// the batch. Depending on your application, you can take compensating actions like delaying and
// retrying. For this simple demo, we just log the failed document keys and continue.
Console.WriteLine(
"Failed to index some of the documents: {0}",
String.Join(", ", e.IndexingResults.Where(r => !r.Succeeded).Select(r => r.Key)));
}
?
私はこのような機能を作成しました:
public void UploadDocuments<T>(SearchIndexClient searchIndexClient, IndexBatch<T> batch, int count) where T : class, IMyAppSearchDocument
{
try
{
searchIndexClient.Documents.Index(batch);
}
catch (IndexBatchException e)
{
if (count == 5) //we will try to index 5 times and give up if it still doesn't work.
{
throw new Exception("IndexBatchException: Indexing Failed for some documents.");
}
Thread.Sleep(5000); //we got an error, wait 5 seconds and try again (in case it's an intermitent or network issue
var retryBatch = e.FindFailedActionsToRetry<T>(batch, arg => arg.ToString());
UploadDocuments(searchIndexClient, retryBatch, count++);
}
}
をしかし、私はこの部分が間違っていると思う:
var retryBatch = e.FindFailedActionsToRetry<T>(batch, arg => arg.ToString());
ありがとうBruce。私はそれが働くことを見る。私はこのコードを変更しました:var retryBatch = e.FindFailedActionsToRetry(バッチ、searchDoc => searchDoc.id); –
richard
皮肉なことに私のコードは指数関数的に後退していましたが、このポストとシンプルさのために、私はそれをわずか5秒に変更しました。私は再びそれを変更します。指数関数的な増加を伴う再試行回数を推薦しますか?私は現在私の鉱山を5に設定している。 – richard
進行中(バッチの最後のインデックス呼び出しよりもアイテムが少ない)であれば、再試行を続けることができ、進捗しない場合にのみ再試行の回数を制限します。その場合、最大リトライ回数は、遅延が指数関数的に増加してからどれくらい待っているかを基準にしてください。指数関数的なものから一定の遅延(例えば、遅延が数分に達した後、またはあなたの作品に見いだされたもののどれか)に切り替えることができる特定の時点を過ぎてください。 –