Skip to content

Doc values (doc['field'] notation) does not work on update #30210

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

Closed
OlivierPetri opened this issue Apr 27, 2018 · 3 comments
Closed

Doc values (doc['field'] notation) does not work on update #30210

OlivierPetri opened this issue Apr 27, 2018 · 3 comments
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache

Comments

@OlivierPetri
Copy link

Elasticsearch version: 6.2

Plugins installed: []

JVM version: 8 (presumably any)

OS version: Any

Description of the problem including expected versus actual behavior:

The doc['field'] notation works well when applied to script_fields but it does not in _update and _update_by_query. It will rather give a null_pointer_exception, no matter what input document.

The notation is introduced as "doc values" in the reference documentation at "Modules/Scripting/Accessing document fields and special variables" as a more performant mean to access document fields.

Steps to reproduce:

PUT sumtest
{
	"mappings" : {
	"doc" : {
	"properties" : {
		"NRA" : { "type" : "integer" },
		"NRB" : { "type" : "integer" },
		"SUMAB" : { "type" : "integer" }
	}
	}
	}
}

PUT sumtest/doc/1
{
	"NRA" : 12,
	"NRB" : 34,
	"SUMAB" : 0,
}

------------

POST sumtest/_update_by_query
{
  "script" : {
      "source" : "doc['SUMAB'] = doc['NRA'] + doc['NRB']",
    "lang": "painless"
  },
  "query": {
    "match_all": {}
  }
}

Provide logs (if relevant):

{
    "error": {
        "root_cause": [
            {
                "type": "script_exception",
                "reason": "runtime error",
                "script_stack": [
                    "doc['SUMAB'] = doc['NRA'] + doc['NRB']",
                    "                   ^---- HERE"
                ],
                "script": "doc['SUMAB'] = doc['NRA'] + doc['NRB']",
                "lang": "painless"
            }
        ],
        "type": "script_exception",
        "reason": "runtime error",
        "script_stack": [
            "doc['SUMAB'] = doc['NRA'] + doc['NRB']",
            "                   ^---- HERE"
        ],
        "script": "doc['SUMAB'] = doc['NRA'] + doc['NRB']",
        "lang": "painless",
        "caused_by": {
            "type": "null_pointer_exception",
            "reason": null
        }
    },
    "status": 500
}

@OlivierPetri
Copy link
Author

You can vary this using other field types, using _update instead of _update_by_query and using doc['SUMAB'].value instead of doc['SUMAB']. The result ist all the same.

@rjernst rjernst added the :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache label Apr 27, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@rjernst
Copy link
Member

rjernst commented Apr 27, 2018

This is a long known issue, most recently discussed in #29290. Update scripts simply do not have access to doc values, since the doc may be coming from the translog. Eventually using doc in an update script will cause a compilation failure instead of a runtime failure, thanks to script contexts now allowing to have different script signatures, but this has not yet been done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache
Projects
None yet
Development

No branches or pull requests

3 participants