Elasticsearch: 6.2.4 "script_score query does not support [params]"

Created on 26 Apr 2018  路  6Comments  路  Source: elastic/elasticsearch

POST /bookdb_index/book/_search
{
"query": {
"function_score": {
"query": {
"multi_match": {
"query": "search engine",
"fields": [
"title",
"summary"
]
}
},
"functions": [
{
"script_score": {
"params": {
"threshold": "2015-07-30"
},
"script": "publish_date = doc['publish_date'].value; num_reviews = doc['num_reviews'].value; if (publish_date > Date.parse('yyyy-MM-dd', threshold).getTime()) { return log(2.5 + num_reviews) }; return log(1 + num_reviews);"}
}
]
}
},
"_source": [
"title",
"summary",
"publish_date",
"num_reviews"
]
}

Most helpful comment

In order to use params with your script you need to specify your script field as a JSON object in the format detailed here: https://www.elastic.co/guide/en/elasticsearch/reference/6.2/modules-scripting-using.html

All 6 comments

In order to use params with your script you need to specify your script field as a JSON object in the format detailed here: https://www.elastic.co/guide/en/elasticsearch/reference/6.2/modules-scripting-using.html

thx

@chroje Can you post the correction?

@chroje Can you post the correction?

@hanxirui, @carlos-olr

Before, with this error:

script_score: {
  params: { 'foo': 'bar'},
  script: '...'
}

After, correct:

script_score: {
  script: {
    params: { 'foo': 'bar'},
    source: '...'
  }
}

Basically, the params have to be underneath the script object, not under the script_score object. In order to do this, you need to switch to using the long form of the script object.

And a big thanks to @colings86, since I was beating my head today against this very error.

Also, in case anyone else runs into this issue, the accessing the param foo above in source is done via params.foo

Was this page helpful?
0 / 5 - 0 ratings