opensearch-project / opensearch-rs

OpenSearch Rust Client
Apache License 2.0
59 stars 34 forks source link

Add new bulk create constructor without optional _id field #245

Closed camerondurham closed 5 months ago

camerondurham commented 5 months ago

Change (latest - revision 2)

Added new create_no_id and new_no_id constructors/helpers to support bulk create operations where no _id field is required.

Change (revision 1)

Changed types to id: Option<S> when _id is optional in the bulk request, otherwise, keep id parameter as String.

This change is making the Bulk operation constructor parameters more closely match the Bulk API, specifically when _id is required or not.

Summarized from the docs: https://www.elastic.co/guide/en/elasticsearch/reference/7.10/docs-bulk.html#bulk-api-request-body

Issues Resolved

Related to, and may close issue #241 .

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. For more information on following Developer Certificate of Origin and signing off your commits, please check here.

dblock commented 5 months ago

@Xtansia take a look?

Regarding a breaking change: if it can be avoided it's best. Then we don't need to do a major release and break users. You can deprecate the old method.

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 79.85%. Comparing base (41417d4) to head (2dc360c). Report is 2 commits behind head on main.

:exclamation: Current head 2dc360c differs from pull request most recent head 56e0316. Consider uploading reports for the commit 56e0316 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #245 +/- ## ========================================== + Coverage 79.71% 79.85% +0.13% ========================================== Files 418 417 -1 Lines 71104 69599 -1505 ========================================== - Hits 56682 55575 -1107 + Misses 14422 14024 -398 ``` | [Flag](https://app.codecov.io/gh/opensearch-project/opensearch-rs/pull/245/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensearch-project) | Coverage Δ | | |---|---|---| | [integration](https://app.codecov.io/gh/opensearch-project/opensearch-rs/pull/245/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensearch-project) | `79.85% <ø> (+0.13%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensearch-project#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

camerondurham commented 5 months ago

It totally makes sense to avoid breaking change. And "making the Rust interface more consistent" doesn't seem to add enough value to warrant a version bump, imo. I'll revise to add new optional constructor from #241 in a non-breaking way.

Testing

And thanks for running test cases, I see I missed updating a bunch of tests will work on that.

I had some trouble running these tests locally so didn't catch this before opening the CR.

https://github.com/opensearch-project/opensearch-rs/actions/runs/8535970109/job/23406883030?pr=245#step:5:446

15  |   ops.push(BulkOperation::index(json!({
    |  __________^^^^^^^^^^^^^^^^^^^^_-
16  | |         "user": "kimchy",
17  | |         "post_date": "2009-11-15T00:00:00Z",
18  | |         "message": "Trying out OpenSearch, so far so good?"
19  | |     }))
    | |______- an argument of type `Option<_>` is missing
Xtansia commented 5 months ago

I also don't feel this warrants a breaking version bump just for this, however there is an opportunity where you could PR a non-breaking change directly into 2.x and make the breaking change in main. Then it'll be usable sooner via a minor version, and the "corrected" version can just wait for whenever we cut a 3.0.0

camerondurham commented 5 months ago

Thanks for the review @Xtansia, I accepted all suggestions and added an entry to the changelog.

opensearch-trigger-bot[bot] commented 5 months ago

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-245-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 28e3d47a54c4fe1ce0a3647c872411602dc6b1e2
# Push it to GitHub
git push --set-upstream origin backport/backport-245-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-245-to-2.x.