Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DR9885 opened this issue Mar 31, 2025 · 3 comments
Closed

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

DR9885 opened this issue Mar 31, 2025 · 3 comments

Comments

@DR9885
Copy link

DR9885 commented Mar 31, 2025

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

@flobernd
Copy link
Member

flobernd commented Apr 1, 2025

Hi @DR9885 , could you please contact the general Elasticsearch support for this?

As far as I know there is no better way of achieving this, since Elasticsearch does not support transactions. This however is unrelated to the .NET client.

Copy link
Contributor

github-actions bot commented Apr 7, 2025

This issue is stale because it has been open 5 days with no activity. Remove stale label or comment or this will be closed in 2 days.

Copy link
Contributor

This issue was closed because it has been stalled for 2 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants