0

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

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.

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.

Steven Jeuris
  • 18,274
  • 9
  • 70
  • 161
  • 1
    I don't think IndexBatchException is thrown in that case, but I'd have to confirm before making this an "official" answer. In the meantime, have you tried it? You can force an item in a batch to fail by trying to merge a non-existent document key. That said, the behavior in a batch-of-size-one case may vary based on the type of failure (something else I need to confirm). – Bruce Johnston Apr 28 '20 at 18:40
  • @BruceJohnston _"You can force an item in a batch to fail by trying to merge a non-existent document key. "_ Good idea! I tried it now, and it throws `IndexBatchException`. The documentation is thus highly misleading. It seems like this exception is thrown for any item in a batch that fails, regardless of batch size, and _one_ of the reasons it is thrown could be heavy indexing load, but also simply for non-existing document keys. – Steven Jeuris Apr 29 '20 at 13:17
  • @BruceJohnston Added an answer based on what I learned. A more "official" answer would still be great. :) To me it seems the documentation needs an overhaul. – Steven Jeuris Apr 29 '20 at 13:39

1 Answers1

0

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 was triggered, which is different behavior than what is documented in two ways:

  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.

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.

Steven Jeuris
  • 18,274
  • 9
  • 70
  • 161