# Elasticsearch document bug: elasticsearch 7.2 plainless script bug

**URL:** <https://discuss.elastic.co/t/elasticsearch-document-bug-elasticsearch-7-2-plainless-script-bug/202452>\
**Category:** Elasticsearch\
**Created:** [October 6, 2019, 2:14pm UTC](https://discuss.elastic.co/t/elasticsearch-document-bug-elasticsearch-7-2-plainless-script-bug/202452 "2019-10-06T14:14:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![laoyang360](https://avatars.discourse-cdn.com/v4/letter/l/a9a28c/32.png) [@laoyang360](https://discuss.elastic.co/u/laoyang360)\
**Post date:** [October 6, 2019, 2:14pm UTC](https://discuss.elastic.co/t/elasticsearch-document-bug-elasticsearch-7-2-plainless-script-bug/202452/1 "2019-10-06T14:14:45Z")

</div>

[elasticsearch 7.2 plainless script bug](https://www.elastic.co/guide/en/elasticsearch/reference/7.2/modules-scripting-using.html#modules-scripting-stored-scripts)

```
`POST _scripts/calculate-score
{
  "script": {
   "lang": "painless",
    "source": "Math.log(_score * 2) + params.my_modifier"
  }
}

GET _scripts/calculate-score

GET _search
{
  "query": {
    "script": {
      "script": {
        "id": "calculate-score",
        "params": {
          "my_modifier": 2
        }
      }
    }
 }
}`

```

when execute \_search, the error report below:

```
    ` "error": {
"root_cause": [
  {
    "type": "script_exception",
    "reason": "compile error",
    "script_stack": [
      "Math.log(_score * 2) + params.my_m ...",
      " ^---- HERE"
    ],
    "script": "Math.log(_score * 2) + params.my_modifier",
    "lang": "painless"
  },
```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 7, 2019, 1:07pm UTC](https://discuss.elastic.co/t/elasticsearch-document-bug-elasticsearch-7-2-plainless-script-bug/202452/2 "2019-10-07T13:07:11Z")

</div>

can you please open an issue in the elasticsearch repository?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![laoyang360](https://avatars.discourse-cdn.com/v4/letter/l/a9a28c/32.png) [@laoyang360](https://discuss.elastic.co/u/laoyang360)\
**Post date:** [October 7, 2019, 2:28pm UTC](https://discuss.elastic.co/t/elasticsearch-document-bug-elasticsearch-7-2-plainless-script-bug/202452/3 "2019-10-07T14:28:12Z")

</div>

thanks for your reply.  
this is not the code bug, just document bug.  
elasticsearch github is not allowed to push this type bugs.

---

<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:** [October 8, 2019, 12:13am UTC](https://discuss.elastic.co/t/elasticsearch-document-bug-elasticsearch-7-2-plainless-script-bug/202452/4 "2019-10-08T00:13:55Z")

</div>

Thanks for the report. I've fixed the docs in [https://github.com/elastic/elasticsearch/pull/47691](https://github.com/elastic/elasticsearch/pull/47691)

---

<div class="post-metadata">

**Author:** ![laoyang360](https://avatars.discourse-cdn.com/v4/letter/l/a9a28c/32.png) [@laoyang360](https://discuss.elastic.co/u/laoyang360)\
**Post date:** [October 8, 2019, 1:18pm UTC](https://discuss.elastic.co/t/elasticsearch-document-bug-elasticsearch-7-2-plainless-script-bug/202452/5 "2019-10-08T13:18:54Z")

</div>

```
# Create the index `hamlet` and add some documents by running the 
# following _bulk commandPUT 
 PUT hamlet-raw/_bulk
{"index":{"_index":"hamlet","_id":0}}
{"line_number":"1.1.1","speaker":"BERNARDO","text_entry":"Whos there?"}
{"index":{"_index":"hamlet","_id":1}}
{"line_number":"1.1.2","speaker":"FRANCISCO","text_entry":"Nay, answer me: stand, and unfold yourself."}
{"index":{"_index":"hamlet","_id":2}}
{"line_number":"1.1.3","speaker":"BERNARDO","text_entry":"Long live the king!"}
{"index":{"_index":"hamlet","_id":3}}
{"line_number":"1.2.1","speaker":"KING CLAUDIUS","text_entry":"Though yet of Hamlet our dear brothers death"}
{"index":{"_index":"hamlet","_id":4}}
{"line_number":"1.2.2","speaker":"KING CLAUDIUS","text_entry":"The memory be green, and that it us befitted"}
{"index":{"_index":"hamlet","_id":5}}
{"line_number":"1.3.1","speaker":"LAERTES","text_entry":"My necessaries are embarkd: farewell:"}
{"index":{"_index":"hamlet","_id":6}}
{"line_number":"1.3.4","speaker":"LAERTES","text_entry":"But let me hear from you."}
{"index":{"_index":"hamlet","_id":7}}
{"line_number":"1.3.5","speaker":"OPHELIA","text_entry":"Do you doubt that?"}
{"index":{"_index":"hamlet","_id":8}}
{"line_number":"1.4.1","speaker":"HAMLET","text_entry":"The air bites shrewdly; it is very cold."}
{"index":{"_index":"hamlet","_id":9}}
{"line_number":"1.4.2","speaker":"HORATIO","text_entry":"It is a nipping and an eager air."}
{"index":{"_index":"hamlet","_id":10}}
{"line_number":"1.4.3","speaker":"HAMLET","text_entry":"What hour now?"}
{"index":{"_index":"hamlet","_id":11}}
{"line_number":"1.5.2","speaker":"Ghost","text_entry":"Mark me."}
{"index":{"_index":"hamlet","_id":12}}
{"line_number":"1.5.3","speaker":"HAMLET","text_entry":"I will."}

# Create a script named `set_is_hamlet` and save it into the cluster 
# state. The script (i) adds a field named `is_hamlet` to each 
# document, (ii) sets the field to "true" if the document has 
# `speaker` equals to "HAMLET", (iii) sets the field to "false" 
# otherwise
# Update all documents in `hamlet` by running the `set_is_hamlet` 
# script

GET hamlet-raw/_search

GET _scripts/set_is_hamlet
DELETE _scripts/set_is_hamlet

POST _scripts/set_is_hamlet
{
   "script": {
	"lang": "painless",
	"source": """
	 if (ctx._source.speaker == "HAMLET") { 
	   ctx._source.is_hamlet = true;
	 } else 
	 {
	   ctx._source.is_hamlet = false;
	 } 
"""
  }
}

# this is ok
POST hamlet-raw/_update_by_query
{
   "script": {
	"lang": "painless",
	"source": """if (ctx._source.speaker == "HAMLET") { ctx._source.is_hamlet = true;} else 
	 {
	   ctx._source.is_hamlet = false;
	 } """
  }
}

# this will "search_phrase_execution_exception compile error" 
GET hamlet-raw/_search
{
  "query": {
	"script_score": {
	  "query":{
		"match_all":{}
	  },
	  "script": {
		"id": "set_is_hamlet"
	  }
	}
  }
}

```

Thanks, I see the bug is fixed on the github.  
But when I auto create another demo, the compile error occor?

---

<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:** [November 5, 2019, 1:19pm UTC](https://discuss.elastic.co/t/elasticsearch-document-bug-elasticsearch-7-2-plainless-script-bug/202452/6 "2019-11-05T13:19:06Z")

</div>

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