Elasticsearch document bug: elasticsearch 7.2 plainless script bug

elasticsearch 7.2 plainless script bug

`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"
  },

can you please open an issue in the elasticsearch repository?

Thanks a lot!

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

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

# 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?

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