本文介绍了具有单个文档的IndexBatch操作会抛出IndexBatchException吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IndexBatchException 文档,例如在调用 IndexAsync 时指出:

The IndexBatchException documentation, e.g., when calling IndexAsync, states:

这是否意味着当 IndexBatch 中只有一个文档时,可以安全地忽略此异常?因为,只有一个文档的 IndexBatch 似乎不可能部分失败.

Does this mean this exception can be safely ignored when there is just a single document in the IndexBatch? Since, it seems impossible for an IndexBatch with just a single document to fail partially.

推荐答案

我尝试通过 Merge 批处理调用 IndexAsync ,该批处理包含单个文档进行更新,但使用不存在的文档密钥( ever-document-ever-throw-indexbatch 108

I tried calling IndexAsync with a Merge batch containing a single document to update, but with a non-existing document key (as recommended by Bruce):

var nonExistingDocument = SomeDocument()
var work = IndexBatch.Merge( nonExistingDocument );

try
{
    await _search.Documents.IndexAsync( work );
}
catch ( IndexBatchException e )
{
    var toRetry = e.FindFailedActionsToRetry( work, d => d.Id);
}

IndexBatchException 已触发,相反,当任何操作都会失败.

  • 当Search Service处于重索引负载时,可能会发生这种情况." 对于不正确的请求,也会发生这种情况.
    1. "Thrown when some of the indexing actions failed, but other actions succeeded and modified the state of the index." Instead, the exception is thrown when any action fails.
    2. "This can happen when the Search Service is under heavy indexing load." This can also happen for incorrect requests.

    但是, FindFailedActionsToRetry 似乎足够聪明,无法建议重试由于错误请求而失败的请求.在上面的代码示例中, toRetry 枚举为空.

    But, FindFailedActionsToRetry is seemingly smart enough to not suggest retrying requests which have failed due to erroneous requests. The toRetry enumeration is empty in the code sample above.

    简而言之,否,无法安全地忽略此异常.该文档具有误导性,如果已更新,那就太好了.

    In short, no, this exception cannot be safely ignored. The documentation is misleading and it would be nice if it were updated.

    这篇关于具有单个文档的IndexBatch操作会抛出IndexBatchException吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-04 10:47
    查看更多