Cannot apply multiply [*] to types [java.lang.Number] and [java.lang.Number]

I am migrating from Elasticsearch version 5.2.1 to latest 7.5.1. My query had special sub-aggregation where I used to multiple score

"aggregations": {
                    "max_score": {
                        "sum": {
                            "script": {
                                "source": "_score * _score",
                                "lang": "painless"
                            }
                        }
                    }
                }

This used to work on 5.2.1 but now getting following error:

"reason": {
                "type": "script_exception",
                "reason": "compile error",
                "script_stack": [
                    "_score * _score",
                    "^---- HERE"
                ],
                "script": "_score * _score",
                "lang": "painless",
                "caused_by": {
                    "type": "class_cast_exception",
                    "reason": "Cannot apply multiply [*] to types [java.lang.Number] and [java.lang.Number]."
                }
            }

How to fix this issue?

 "script": "_score.floatValue() * _score.floatValue()",

seems to be working. Is this the right way?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.