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 API should check the syntax in case of scripted updates #28740

Closed
astefan opened this issue Feb 19, 2018 · 4 comments
Closed

_update API should check the syntax in case of scripted updates #28740

astefan opened this issue Feb 19, 2018 · 4 comments
Labels
>bug :Data Management/Indices APIs APIs to create and manage indices and templates help wanted adoptme

Comments

@astefan
Copy link
Contributor

astefan commented Feb 19, 2018

Elasticsearch version (bin/elasticsearch --version): 6.1.2

Plugins installed: []

Description of the problem including expected versus actual behavior:

The _update API doesn't seem to reject a command that is wrong. Actually, this example comes from The Definitive Guide (which I know it's WIP), but still the ES API should reply back with an error for such a command:

POST /website/blog/1/_update
{
  "script": "ctx.op = ctx._source.views == params.count ? 'delete' : 'none'",
  "params": {
    "count": 1
  }
}

This returns:

{
  "_index": "website",
  "_type": "blog",
  "_id": "1",
  "_version": 2,
  "result": "noop",
  "_shards": {
    "total": 0,
    "successful": 0,
    "failed": 0
  }
}

Debugging this with Debug.explain(params) shows that there is no params registered. Which, in fact, is fine since the syntax is incorrect: there shouldn't be any params definitions at the root level, but inside script itself. The correct syntax should be:

POST /website/blog/1/_update
{
  "script": {
    "source": "ctx.op = ctx._source.views == params.count ? 'delete' : 'none'",
    "params": {
      "count": 1
    }
  }
}
@astefan astefan added the >bug label Feb 19, 2018
@javanna javanna added :Data Management/Indices APIs APIs to create and manage indices and templates help wanted adoptme labels Mar 1, 2018
@javanna
Copy link
Member

javanna commented Mar 1, 2018

cc @elastic/es-core-infra

@rjernst
Copy link
Member

rjernst commented Mar 8, 2018

For anyone interested in fixing this, the lenient code is in UpdateRequest.fromXContent. The if/elseifs in the while loop need to handle unknown keys. Better yet would be to convert this to ObjectParser.

@nikhilbarar
Copy link

Is this issue still open? I'd like to pick this up.

@rjernst
Copy link
Member

rjernst commented Mar 15, 2018

@nikhilbarar Please feel free to open a PR for this (or any other issues marked with adoptme). Thanks for picking this up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Data Management/Indices APIs APIs to create and manage indices and templates help wanted adoptme
Projects
None yet
Development

No branches or pull requests

4 participants