具有单个文档的IndexBatch操作会抛出IndexBatchException吗? [英] Would an IndexBatch operation with a single document ever throw IndexBatchException?

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

问题描述

<代码> IndexBatchException 文档,例如在调用 IndexAsync 时指出:

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

某些索引操作失败时引发,但其他操作成功并修改了索引状态.当Search Service的索引编制负担很重时,可能会发生这种情况.显式捕获此异常并检查其IndexResult属性很重要.此属性报告批处理中每个索引操作的状态,从而可以确定部分失败后的索引状态.

Thrown when some of the indexing actions failed, but other actions succeeded and modified the state of the index. This can happen when the Search Service is under heavy indexing load. It is important to explicitly catch this exception and check its IndexResult property. This property reports the status of each indexing action in the batch, making it possible to determine the state of the index after a partial failure.

这是否意味着当 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 ,该批处理包含单个文档进行更新,但使用不存在的文档密钥(

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 已触发,

IndexBatchException was triggered, which is different behavior than what is documented in two ways:

  1. 某些索引操作失败时引发,但其他操作成功,并修改了索引状态." 相反,当任何操作都会失败.
  2. 当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吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆