# Error when accessing \_index in script\_score

**URL:** <https://discuss.elastic.co/t/error-when-accessing--index-in-script-score/63109>\
**Category:** Elasticsearch\
**Created:** [October 15, 2016, 2:18pm UTC](https://discuss.elastic.co/t/error-when-accessing--index-in-script-score/63109 "2016-10-15T14:18:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![NickW](https://avatars.discourse-cdn.com/v4/letter/n/8e7dd6/32.png) [@NickW](https://discuss.elastic.co/u/NickW)\
**Post date:** [October 15, 2016, 2:18pm UTC](https://discuss.elastic.co/t/error-when-accessing--index-in-script-score/63109/1 "2016-10-15T14:18:28Z")

</div>

Using latest rc1, there's an error if a `script_score` script references `_index` (for [text scoring](https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-advanced-scripting.html)):

`illegal_argument_exception - Variable [_index] is not defined`

Sample query:

```
GET _search
{
  "query": {
    "function_score": {
      "query": { 
        "match": { "title": "apple" }
      },
      "functions": [ 
        {
          "script_score": {
            "script": {
              "lang": "painless",
              "inline": "_index['title'].docCount()"
            }
          }
        }
      ]
    }
  }
}

```

Anyone know why there's an error?

---

<div class="post-metadata">

**Author:** ![YanhaoYang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yanhaoyang/32/13910_2.png) [@YanhaoYang](https://discuss.elastic.co/u/YanhaoYang)\
**Post date:** [December 15, 2016, 9:32am UTC](https://discuss.elastic.co/t/error-when-accessing--index-in-script-score/63109/2 "2016-12-15T09:32:02Z")

</div>

It seems `_index` is not supported in painless language. Change "lang" to "groovy", and the query will work. Also note that you need to turn on groovy inline script in ES 5.

---

<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:** [July 5, 2017, 10:04pm UTC](https://discuss.elastic.co/t/error-when-accessing--index-in-script-score/63109/3 "2017-07-05T22:04:55Z")

</div>


