Skip to content
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

Add script fields support for multi search request #632

Merged
merged 4 commits into from
Sep 30, 2023

Conversation

VachaShah
Copy link
Collaborator

@VachaShah VachaShah commented Sep 21, 2023

Description

Adding script_fields support to multi search requests.

Issues Resolved

Resolves #617

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.

Signed-off-by: Vacha Shah <vachshah@amazon.com>
Signed-off-by: Vacha Shah <vachshah@amazon.com>
Signed-off-by: Vacha Shah <vachshah@amazon.com>
@VachaShah
Copy link
Collaborator Author

I get all shards failed error with a 400 at https://github.com/opensearch-project/opensearch-java/pull/632/files#diff-6dd4651c7690aae6641c827a2197719d2331288e495c6f4c2b6032e56a8f098cR214. @reta Any suggestions if I am using the script_fields wrong?

@reta
Copy link
Collaborator

reta commented Sep 22, 2023

@reta Any suggestions if I am using the script_fields wrong?

AFAIK it seems to be request serialization issue, notice {} in the beginning:

{}
{"query":{"bool":{"filter":[{"term":{"size":{"value":"small"}}}]}},"script_fields":{"test1":{"script":{"params":{"inc":1},"lang":"painless","source":"ctx._source.quantity += params.inc"}}}}

@reta
Copy link
Collaborator

reta commented Sep 22, 2023

AFAIK it seems to be request serialization issue, notice {} in the beginning:

Oops, my bad sorry, this is _msearch, the format is correct

Map<String, ScriptField> scriptFields = new HashMap<>();
scriptFields.put("test1", new ScriptField.Builder().script(Script.of(s -> s.inline(new InlineScript.Builder()
.lang("painless")
.source("ctx._source.quantity += params.inc")
Copy link
Collaborator

@reta reta Sep 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VachaShah that should make it (apologies for the wrong hint before):

Suggested change
.source("ctx._source.quantity += params.inc")
.source("doc['quantity'].value + params.inc")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @reta, that works!!

Signed-off-by: Vacha Shah <vachshah@amazon.com>
@dblock dblock merged commit 8c97111 into opensearch-project:main Sep 30, 2023
37 checks passed
@reta reta added the backport 2.x Backport to 2.x branch label Sep 30, 2023
@opensearch-trigger-bot
Copy link

The backport to 2.x failed:

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

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
pushd ../.worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-632-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 8c97111f53f8d91f2550d8232aaf82daf8d7f384
# Push it to GitHub
git push --set-upstream origin backport/backport-632-to-2.x
# Go back to the original working tree
popd
# 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-632-to-2.x.

VachaShah added a commit to VachaShah/opensearch-java that referenced this pull request Oct 3, 2023
…t#632)

* Adding script_fields support for mseearch request with tests

Signed-off-by: Vacha Shah <vachshah@amazon.com>

* Fixing logger in Search sample

Signed-off-by: Vacha Shah <vachshah@amazon.com>

* Fixing build

Signed-off-by: Vacha Shah <vachshah@amazon.com>

* Fixing tests

Signed-off-by: Vacha Shah <vachshah@amazon.com>

---------

Signed-off-by: Vacha Shah <vachshah@amazon.com>
VachaShah added a commit that referenced this pull request Oct 3, 2023
* Adding script_fields support for mseearch request with tests



* Fixing logger in Search sample



* Fixing build



* Fixing tests



---------

Signed-off-by: Vacha Shah <vachshah@amazon.com>
@VachaShah VachaShah deleted the add-script-fields-msearch branch October 12, 2023 22:25
@BrendonFaleiro BrendonFaleiro mentioned this pull request Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] add script_fields to _msearch queries
3 participants