Skip to content

Script Error when using unsigned long in a scripted_metric #64347

@hendrikmuhs

Description

@hendrikmuhs

Executing a scripted_metric on an unsigned_long field fails, while the same works for long.

Minimal repro case:

PUT ul_test
{
  "mappings": {
    "properties": {
      "a": {
        "type": "unsigned_long"
      }
    }
  }
}

POST ul_test/_doc/1
{
  "a": 42
}

PUT l_test
{
  "mappings": {
    "properties": {
      "a": {
        "type": "long"
      }
    }
  }
}

POST l_test/_doc/1
{
  "a": 42
}

GET l_test/_search
{
  "aggs": {
    "sqrt": {
      "scripted_metric": {
        "init_script": "state.sqrd = []",
        "map_script": "state.sqrd.add(doc.a.value * doc.a.value)",
        "combine_script": "state.sqrd",
        "reduce_script": "def sum = 0.0; for(l in states){ for(a in l) { sum += a}} return sum"
      }
    }
  }
}

GET ul_test/_search
{
  "aggs": {
    "sqrt": {
      "scripted_metric": {
        "init_script": "state.sqrd = []",
        "map_script": "state.sqrd.add(doc.a.value * doc.a.value)",
        "combine_script": "state.sqrd",
        "reduce_script": "def sum = 0.0; for(l in states){ for(a in l) { sum += a}} return sum"
      }
    }
  }
}

error:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "script_exception",
        "reason" : "runtime error",
        "script_stack" : [
          "state.sqrd.add(doc.a.value * doc.a.value)",
          "                    ^---- HERE"
        ],
        "script" : "state.sqrd.add(doc.a.value * doc.a.value)",
        "lang" : "painless",
        "position" : {
          "offset" : 20,
          "start" : 0,
          "end" : 41
        }
      }
    ],

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions