Cannot access _score in expression script with 7.x

Hi.

We used to order a terms aggregation by a "max_score" sub-aggregation in Elasticsearch 6.5:

{
  "size": 0,
  "query": { ... },
  "aggregations": {
    "assets": {
      "terms": {
        "field": "type_of",
        "size": 10,
        "order": [
          {
            "max_score": "desc"
          },
          {
            "_key": "asc"
          }
        ]
      },
      "aggregations": {
        "max_score": {
          "max": {
            "script": {
              "source": "_score",
              "lang": "expression"
            }
          }
        }
      }
    }
  }
}

We're in the process of upgrading to 7.x and trying to use _score causes an error now:

Caused by: org.elasticsearch.script.ScriptException: link error
...
Caused by: java.text.ParseException: Unknown variable [_score]

What's the matter here? Is that a bug?

/edit: BTW, using painless instead works. But is it as fast as the expression script?

Thanks!

Looks like this was accidentally lost in https://github.com/elastic/elasticsearch/pull/33820. Should be able to get a PR up soon, but it probably won't be fixed until 7.3.0.

In this case painless should have performance parity with expressions as they use the same source for accessing _score.

Thank you @rjernst and @Jack_Conradson, I'll go with painless in the meantime.

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