# Cannot access \_score in expression script with 7.x

**URL:** <https://discuss.elastic.co/t/cannot-access-score-in-expression-script-with-7-x/183134>\
**Category:** Elasticsearch\
**Created:** [May 28, 2019, 3:13pm UTC](https://discuss.elastic.co/t/cannot-access-score-in-expression-script-with-7-x/183134 "2019-05-28T15:13:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cbley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbley/32/33102_2.png) [@cbley](https://discuss.elastic.co/u/cbley)\
**Post date:** [May 28, 2019, 3:13pm UTC](https://discuss.elastic.co/t/cannot-access-score-in-expression-script-with-7-x/183134/1 "2019-05-28T15:13:39Z")

</div>

Hi.

We used to order a terms aggregation by a "max\_score" sub-aggregation in Elasticsearch 6.5:

```auto
{
  "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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [May 28, 2019, 5:09pm UTC](https://discuss.elastic.co/t/cannot-access-score-in-expression-script-with-7-x/183134/2 "2019-05-28T17:09:55Z")

</div>

Looks like this was accidentally lost in [https://github.com/elastic/elasticsearch/pull/33820](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.

---

<div class="post-metadata">

**Author:** ![Jack\_Conradson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_conradson/32/47236_2.png) [@Jack\_Conradson](https://discuss.elastic.co/u/Jack_Conradson)\
**Post date:** [May 28, 2019, 8:42pm UTC](https://discuss.elastic.co/t/cannot-access-score-in-expression-script-with-7-x/183134/3 "2019-05-28T20:42:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cbley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbley/32/33102_2.png) [@cbley](https://discuss.elastic.co/u/cbley)\
**Post date:** [May 29, 2019, 6:10am UTC](https://discuss.elastic.co/t/cannot-access-score-in-expression-script-with-7-x/183134/4 "2019-05-29T06:10:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 26, 2019, 6:20am UTC](https://discuss.elastic.co/t/cannot-access-score-in-expression-script-with-7-x/183134/5 "2019-06-26T06:20:09Z")

</div>

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