Skip to content

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

@astefan

Description

@astefan

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
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions