1

We have had this query for a long time

{
  "size": 50,
  "query": {
   "match_all": {}
  },
  "version": false,
  "seq_no_primary_term": false,
  
  "sort": [
    {
      "_script": {
        "script": {
          "source": "(doc[params.f].size() != 0) ? (params.m['' + doc[params.f].value] ?: params.o): params.o",
          "lang": "painless",
          "params": {
            "f": "scoreSerial",
            "m": {
              "0": "UNDEFINED",
              "1": "FRUSTRATED",
              "2": "TOLERATED",
              "3": "SATISFIED"
            },
            "o": "ZZZZZ"
          }
        },
        "type": "string",
        "order": "asc"
      }
    }
  ]
} 

This suddenly stopped working with the error

{
  "error" : {
    "root_cause" : [
      {
        "type" : "bootstrap_method_error",
        "reason" : "bootstrap_method_error: CallSite bootstrap method initialization exception"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "visit-global-standard-w2022.31",
        "node" : "olbLlZh7RYuwaf5S-B9v8g",
        "reason" : {
          "type" : "script_exception",
          "reason" : "runtime error",
          "script_stack" : [
            "(doc[params.f].size() != 0) ? (params.m['' + doc[params.f].value] ?: params.o): params.o",
            "                                                          ^---- HERE"
          ],
          "script" : "(doc[params.f].size() != 0) ? (params.m['' + doc[params.f].value] ?: params.o): params.o",
          "lang" : "painless",
          "position" : {
            "offset" : 58,
            "start" : 0,
            "end" : 88
          },
          "caused_by" : {
            "type" : "bootstrap_method_error",
            "reason" : "bootstrap_method_error: CallSite bootstrap method initialization exception"
          }
        }
      }
    ],
    "caused_by" : {
      "type" : "bootstrap_method_error",
      "reason" : "bootstrap_method_error: CallSite bootstrap method initialization exception"
    }
  },
  "status" : 400
}

The mapping of scoreSerial is

 "scoreSerial" : {
        "type" : "long"
 }

It was working for more than 3 years. We are now on the 7.10 (for more than 6 months, when the above script was working) ES version. But suddenly it started to fail. The strange thing is that it is not happening in all environments. Is it some java version related or something else? We can not also reproduce this locally.

2
  • 2
    I was going to ask whether ALL documents have a scoreSerial field with a non-null value, but if you have doc[params.f].size() != 0 you should be protected. Can you replace '' + doc[params.f].value by doc[params.f].value.toString()? Commented Sep 8, 2022 at 11:23
  • 1
    Thanks for your comment. Yes, we have non-null value for all fo them. We tried various things along with .toString() and it works. We are not sure why suddenly this query started to fail. Commented Sep 8, 2022 at 12:11

1 Answer 1

2

It might have to do with type coercion, I've seen similar problems in the past (although not with painless but groovy), so simply replacing

'' + doc[params.f].value

by

doc[params.f].value.toString()

might do the trick

(i.e. explicitly getting the string version of the doc value instead of relying on type coercion). What you did should work according to the docs, though.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.