Add generic script support for update/upsert operations in OpenSearch sink#6744
Merged
dinujoh merged 2 commits intoApr 10, 2026
Merged
Conversation
✅ License Header Check PassedAll newly added files have proper license headers. Great work! 🎉 |
76a6246 to
78d49a6
Compare
dlvenable
requested changes
Apr 9, 2026
| } | ||
|
|
||
| private BulkOperation getBulkOperationForAction(final String action, | ||
| BulkOperation getBulkOperationForAction(final String action, |
Member
There was a problem hiding this comment.
Rather than expose this to test using package private, what would be the effort to move this to its own class - say BulkOperationFactory?
Member
Author
There was a problem hiding this comment.
Will refactor BulkOperationFactory as a follow-up to keep this PR scoped.
… sink
Adds the ability to configure a script on the OpenSearch sink that gets
applied to update and upsert bulk operations. This is a generic mechanism
that passes script source and params through to OpenSearch's bulk API.
Script language is hardcoded to painless. The event document is
automatically passed as params.doc. scripted_upsert is always true
so the script runs on every write including the first create.
Script param values support ${} expression syntax for dynamic
resolution from event fields or metadata.
Configuration example:
sink:
- opensearch:
hosts: ["https://localhost:9200"]
index: "my-index"
action: "upsert"
document_id: "${/id}"
script:
source: "ctx._source.putAll(params.doc); ctx._source.source = params.table"
params:
table: "${getMetadata(\"table_name\")}"
Resolves opensearch-project#3563
Signed-off-by: Dinu John <86094133+dinujoh@users.noreply.github.com>
b1b66a1 to
9eef437
Compare
dlvenable
previously approved these changes
Apr 9, 2026
… expectations Remove unused imports (ScriptConfiguration, HashMap, Map) from OpenSearchSink. Update expected compressed bulk request sizes in integration tests to account for the additional resolvedScriptParameters field in SerializedJsonImpl. Signed-off-by: Dinu John <86094133+dinujoh@users.noreply.github.com>
917ecdd to
57a8d87
Compare
dlvenable
approved these changes
Apr 9, 2026
oeyh
approved these changes
Apr 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds generic script support for update/upsert operations in the OpenSearch sink. When configured, the sink attaches an inline script (https://opensearch.org/docs/latest/api-reference/document-apis/update-document/#script-example) to bulk update/upsert requests.
Key behaviors:
Configuration
Examples
First write → {"id": 1, "name": "test", "write_count": 1}
Second write → {"id": 1, "name": "updated", "write_count": 2}
2. Conditional price update — only update if lower
Events from products table:
Events from pricing table:
Result in OpenSearch:
Delete pricing:
Result:
Issues Resolved
Resolves #3563
Check List
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.