Skip to content

[FEATURE] Elastic 8 Client - Atomic Insert Option #8483

Closed as not planned
Closed as not planned
@DR9885

Description

@DR9885

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions