# Painless script don't have access to a \_index variable and groovy is depreciated in 5.4

**URL:** <https://discuss.elastic.co/t/painless-script-dont-have-access-to-a--index-variable-and-groovy-is-depreciated-in-5-4/86564>\
**Category:** Elasticsearch\
**Created:** [May 21, 2017, 10:19am UTC](https://discuss.elastic.co/t/painless-script-dont-have-access-to-a--index-variable-and-groovy-is-depreciated-in-5-4/86564 "2017-05-21T10:19:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sushant\_Pritmani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sushant_pritmani/32/18408_2.png) [@Sushant\_Pritmani](https://discuss.elastic.co/u/Sushant_Pritmani)\
**Post date:** [May 21, 2017, 10:19am UTC](https://discuss.elastic.co/t/painless-script-dont-have-access-to-a--index-variable-and-groovy-is-depreciated-in-5-4/86564/1 "2017-05-21T10:19:13Z")

</div>

I am indexing 85,000 documents with following settings and mapping:

```
PUT /ap_dataset/
{
"settings": {
"index": {
  "store": {
    "type": "fs"
  },
  "number_of_shards": 1,
  "number_of_replicas": 1
},
"analysis": {
  "analyzer": {
    "my_english": { 
      "type": "english",
      "stopwords_path": "stoplist.txt" 
    }
   }
  }
 }
}

PUT /ap_dataset/hw1/_mapping
{
"hw1": {
"properties": {
  "docno": {
    "type": "keyword",
    "store": true
  },
  "text": {
    "type": "text",
    "store": true,
    "term_vector": "with_positions_offsets_payloads",
    "analyzer": "my_english",
    "fielddata": true
    
   }
  }
 }
}

```

I am using ElasticSearch 5.4. I am trying to replace default scoring with custom scoring in following manner:

```
GET /ap_dataset/document/_search
{
"query": {
"function_score": {
  "query": {
    "match": {
      "text": "cow"
    }
  },
  "boost_mode": "replace",
  "functions": [
    {
      "script_score": {
        "script": "_index['text']['cow'].tf()"
      }
    }
   ]
  }
 }
}

```

But I am getting the following error:

```
 {
 "error": {
"root_cause": [
  {
    "type": "script_exception",
    "reason": "compile error",
    "script_stack": [
      "_index['text']['fox'].tf( ...",
      "^---- HERE"
    ],
    "script": "_index['text']['fox'].tf()",
    "lang": "painless"
  }
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
  {
    "shard": 0,
    "index": "ap_dataset",
    "node": "zhCmVrZgRC-YQU5BOaz49w",
    "reason": {
      "type": "query_shard_exception",
      "reason": "script_score: the script could not be loaded",
      "index_uuid": "-TpUstdDQVSZnLwvLKWkPA",
      "index": "ap_dataset",
      "caused_by": {
        "type": "script_exception",
        "reason": "compile error",
        "script_stack": [
          "_index['text']['fox'].tf( ...",
          "^---- HERE"
        ],
        "script": "_index['text']['fox'].tf()",
        "lang": "painless",
        "caused_by": {
          "type": "illegal_argument_exception",
          "reason": "Variable [_index] is not defined."
        }
      }
    }
  }
 ]
},
"status": 400
}

```

Any pointers for the problem?  
TIA

---

<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 23, 2017, 3:42am UTC](https://discuss.elastic.co/t/painless-script-dont-have-access-to-a--index-variable-and-groovy-is-depreciated-in-5-4/86564/2 "2017-05-23T03:42:31Z")

</div>

Access to `_index` in scripts has been removed for 6.0 and deprecated in 5.x (next release 5.5.0). The documentation has been updated to [use a ScriptEngine](https://www.elastic.co/guide/en/elasticsearch/reference/5.x/modules-scripting-engine.html) to accomplish the same goal.

---

<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 20, 2017, 3:42am UTC](https://discuss.elastic.co/t/painless-script-dont-have-access-to-a--index-variable-and-groovy-is-depreciated-in-5-4/86564/3 "2017-06-20T03:42:32Z")

</div>

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