Closed as not planned
Description
Is your feature request related to a problem? Please describe.
Need a way to fail CreateMany if any inserts fail.
Describe the solution you'd like
CreateMany has Option to pass, to enable atomic writes
Describe alternatives you've considered
Deleting records after response comes, but this slows down performance by forcing a second call.
public async Task<Result> InsertAllAsync(TE[] objs, CancellationToken ct)
{
var res = await _client.BulkAsync(
b => b.Index(_dbName)
.CreateMany(objs)
.Refresh(GetRefresh()), ct).ConfigureAwait(false);
var allIds = objs.Select(x => x.Id).ToArray();
var result = new Result { PassedIds = allIds };
if (!res.IsValidResponse)
{
// TODO: Remove Hack once elastic team gives recommendation:
var failedIds = res.ItemsWithErrors.Select(x => x.Id).ToArray();
var passedIds = allIds.Except(failedIds).ToArray();
await DeleteAllAsync(passedIds, ct);
result.PassedIds = [];
result.FailedIds = allIds;
}
return result;
}
Additional context
N/A