Skip to content

Painless script_fields don't have access to a _source variable #20068

@Bargs

Description

@Bargs

Elasticsearch version: master

Plugins installed: none

JVM version: 1.8.0_60

OS version: OSX El Capitan

Description of the problem including expected versus actual behavior:

According to the docs script_fields can access the document _source via a _source keyword. When attempting this with a Painless script, I get a Variable [_source] is not defined. error.

Steps to reproduce:

  1. Execute a query with a painless script_field that attempts to access _source, something like this:
    "script_fields": {
        "scriptip": {
            "script": {
                "inline": "return _source.ip;",
                "lang": "painless"
            }
        }
    }

Provide logs (if relevant):

{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "compile error",
        "script_stack": [
          "return _source.ip;",
          "       ^---- HERE"
        ],
        "script": "return _source.ip;",
        "lang": "painless"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query_fetch",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "logstash-0",
        "node": "00s71MPnSRenvz6mflLQeQ",
        "reason": {
          "type": "script_exception",
          "reason": "compile error",
          "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "Variable [_source] is not defined."
          },
          "script_stack": [
            "return _source.ip;",
            "       ^---- HERE"
          ],
          "script": "return _source.ip;",
          "lang": "painless"
        }
      }
    ],
    "caused_by": {
      "type": "script_exception",
      "reason": "compile error",
      "caused_by": {
        "type": "illegal_argument_exception",
        "reason": "Variable [_source] is not defined."
      },
      "script_stack": [
        "return _source.ip;",
        "       ^---- HERE"
      ],
      "script": "return _source.ip;",
      "lang": "painless"
    }
  },
  "status": 500
}

Describe the feature:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions