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

Update by query should support short script form and doc #24898

Closed
clintongormley opened this issue May 26, 2017 · 13 comments
Closed

Update by query should support short script form and doc #24898

clintongormley opened this issue May 26, 2017 · 13 comments
Labels
:Distributed/CRUD A catch all label for issues around indexing, updating and getting a doc by id. Not search. >enhancement good first issue low hanging fruit help wanted adoptme

Comments

@clintongormley
Copy link

The script parameter in update-by-query requires a full script object, instead of allowing the simple script form:

"script": "ctx._source.foo=5"

We should be using the same script parser we use every else, which would take care of this automatically.

Also, any reason why we don't support partial doc updates with the doc parameter`?

@clintongormley clintongormley added :Distributed/CRUD A catch all label for issues around indexing, updating and getting a doc by id. Not search. help wanted adoptme >enhancement good first issue low hanging fruit labels May 26, 2017
@rjernst
Copy link
Member

rjernst commented May 26, 2017

What do you mean by partial updates? doc is doc values, ie already indexed values.

@clintongormley
Copy link
Author

No, I mean the doc parameter which exists in the update query, as in:

POST index/type/id/_update
{
  "doc": {
    "status": "published"
  }
}

This request would merge the doc object with the _source. It's currently not supported by update-by-query

@rjernst
Copy link
Member

rjernst commented May 26, 2017

Ok, thanks for the clarification. So this would happen outside of the script itself.

@pozhidaevak
Copy link
Contributor

Hi,
I want to make this issue my first contribution to the project. Has anyone started work on this issue? Is it ok if I start working on it? It will probably take some time for me to understand the issue and familiarise myself with the code.

@nik9000
Copy link
Member

nik9000 commented Sep 25, 2017

This is two issues:

  1. Update-by-query doesn't support doc style updates like those mentioned here.
  2. Update-by-query doesn't support a short form for specifying the script.

The reasoning behind the first point is that we wanted to keep update-by-query simple. We can do it though. I don't think solving the first point would be a good first contribution, but it is a thing we can do.

The second point is fine for a first contribution because it is just extra parsing without any additional changes. I don't know why it doesn't work now but to fix it I'd hunt down how we do parsing with _update and see if we can use that for _update_by_query.

@pozhidaevak
Copy link
Contributor

Thanks, @nik9000.
It seems that _update_by_query uses static function RestUpdateByQueryAction::parseScript(Map<String, Object>) to parse script tag. This function is used only in this place.
I haven't found parsing of script field in RestUpdateAction class.
I'll try to find the solution that reuses the same code as in other parts of the project.
For now, I think the best way is to initialize XContentParser and use Script.parse() function.

pozhidaevak pushed a commit to pozhidaevak/elasticsearch that referenced this issue Sep 29, 2017
nik9000 pushed a commit that referenced this issue Oct 11, 2017
Update by Query is modified to accept short `script` parameter.

Closes issue #24898
nik9000 pushed a commit that referenced this issue Oct 11, 2017
Update by Query is modified to accept short `script` parameter.

Closes issue #24898
@dakrone
Copy link
Member

dakrone commented Mar 20, 2018

This should be closed by #26841

@dakrone dakrone closed this as completed Mar 20, 2018
@olee
Copy link

olee commented Mar 21, 2018

And what about the doc parameter that _update accepts but not _update_by_query?

@0bsearch
Copy link

0bsearch commented Jul 2, 2018

@nik9000 any updates on support for doc?

@nik9000
Copy link
Member

nik9000 commented Jul 2, 2018

And what about the doc parameter that _update accepts but not _update_by_query?

We've talked about this in the past and not been too keen on it.

@est
Copy link

est commented Jan 26, 2021

support only script will yield stupid "too many scripts OMG cant compile" errors.

@souenzzo
Copy link

Still waiting support for doc.

If you are here, you probably want to use this script:

{
  source: "for (k in params.keySet()) {ctx._source[k] = params[k]}",
  params: {a: 1, b: 2 ...}
}

@Trass3r
Copy link

Trass3r commented Feb 7, 2024

Thanks @souenzzo!
It's important to note though that unlike _update this doesn't merge partial objects, it just overwrites.

  "script": {
    "source": "for (k in params.keySet()) {ctx._source[k] = params[k]}",
    "params": {
      "obj": {
        "field2": "val"
      }
    }
  }

https://www.reddit.com/r/elasticsearch/comments/upig3f/how_to_merge_objects_in_painless/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed/CRUD A catch all label for issues around indexing, updating and getting a doc by id. Not search. >enhancement good first issue low hanging fruit help wanted adoptme
Projects
None yet
Development

No branches or pull requests

10 participants