# Compile Error Supplying Param to Script

**URL:** <https://discuss.elastic.co/t/compile-error-supplying-param-to-script/172872>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [March 18, 2019, 10:52pm UTC](https://discuss.elastic.co/t/compile-error-supplying-param-to-script/172872 "2019-03-18T22:52:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Teddis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/teddis/32/27902_2.png) [@Teddis](https://discuss.elastic.co/u/Teddis)\
**Post date:** [March 18, 2019, 10:52pm UTC](https://discuss.elastic.co/t/compile-error-supplying-param-to-script/172872/1 "2019-03-18T22:52:51Z")

</div>

I'm using ES 6.2.4 and online documentation for this version says one should use parameters to optimize scripting. I'm getting a compile error when trying to do so...

```
GET group/_search
{
  "min_score": 1,
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "must": [
            {
              "terms": {
                "itemId": [
                  "176947"
                ]
              }
            },
            {
              "match": {
                "name": {
                  "query": "soft drinks",
                  "operator": "and",
                  "fuzziness": "AUTO",
                  "prefix_length": 2
                }
              }
            }
          ]
        }
      },
      "script_score": {
        "script": {
          "params": {
            "terms": 2
          },
          "source": "terms / (float)doc['name.length'].value"
        }
      }
    }
  }
}

```

Result:

```
{
  "error": {
    "root_cause": [
      {
        "type": "script_exception",
        "reason": "compile error",
        "script_stack": [
          "terms / (float)doc['name. ...",
          "^---- HERE"
        ],
        "script": "terms / (float)doc['name.length'].value",
        "lang": "painless"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "group_20190318_150630",
        "node": "L0vkzTvaRTWOBHtU0PYBdQ",
        "reason": {
          "type": "query_shard_exception",
          "reason": "script_score: the script could not be loaded",
          "index_uuid": "1Gh7dOv3QXOo_8Ta8wm1_w",
          "index": "group_20190318_150630",
          "caused_by": {
            "type": "script_exception",
            "reason": "compile error",
            "script_stack": [
              "terms / (float)doc['name. ...",
              "^---- HERE"
            ],
            "script": "terms / (float)doc['name.length'].value",
            "lang": "painless",
            "caused_by": {
              "type": "illegal_argument_exception",
              "reason": "Variable [terms] is not defined."
            }
          }
        }
      }
    ],
    "caused_by": {
      "type": "script_exception",
      "reason": "compile error",
      "script_stack": [
        "terms / (float)doc['name. ...",
        "^---- HERE"
      ],
      "script": "terms / (float)doc['name.length'].value",
      "lang": "painless",
      "caused_by": {
        "type": "illegal_argument_exception",
        "reason": "Variable [terms] is not defined."
      }
    }
  },
  "status": 400
}
```

---

<div class="post-metadata">

**Author:** ![Teddis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/teddis/32/27902_2.png) [@Teddis](https://discuss.elastic.co/u/Teddis)\
**Post date:** [March 18, 2019, 10:59pm UTC](https://discuss.elastic.co/t/compile-error-supplying-param-to-script/172872/2 "2019-03-18T22:59:13Z")

</div>

Sigh... The problem is that the online documentation is faulty. [How to write scripts | Elasticsearch Guide [master] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-using.html#_script_parameters)

The example shows:

> "source": "doc['my\_field'] \* multiplier"

And should be:

> "source": "doc['my\_field'] \* params.multiplier"

---

<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:** [April 15, 2019, 10:59pm UTC](https://discuss.elastic.co/t/compile-error-supplying-param-to-script/172872/3 "2019-04-15T22:59:18Z")

</div>

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