想在function_score里面使用script_score,
请求是:
报错是:
然后不知道是不是配置的问题,在elasticsearch.yml里面加上了:
但是重启会报错,
请问要如何正确使用script呢?
请求是:
curl -H "Content-Type: application/json" -XGET 'localhost:9200/test_index/metaDoc/_search?pretty' -d '
{
"explain": true,
"query": {
"function_score": {
"query": {
"bool": {
"must": [ {
"match_phrase": {
"docName": "活动"
}
}
]
}
},
"functions": [
{
"field_value_factor": {
"field": "clicks",
"modifier": "log1p",
"factor": 2,
"missing": 0
}
},
{
"script_score" : {
"script" : {
"params": {
"a": 4,
"b": 1
},
"inline": "params.a / doc['clicks'].value"
}
}
}
],
"boost_mode": "sum",
"score_mode": "sum"
}
},
"size": 4
}'
报错是:
{
"error" : {
"root_cause" : [
{
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
"params.a / doc[clicks].value",
" ^---- HERE"
],
"script" : "params.a / doc[clicks].value",
"lang" : "painless"
}
],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query",
"grouped" : true,
"failed_shards" : [
{
"shard" : 0,
"index" : "test_index",
"node" : "gDlILShpRcaaiuzMO75Jcw",
"reason" : {
"type" : "query_shard_exception",
"reason" : "script_score: the script could not be loaded",
"index_uuid" : "0nqvfTFlSPmm5rZXV_R6mQ",
"index" : "test_index",
"caused_by" : {
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
"params.a / doc[clicks].value",
" ^---- HERE"
],
"script" : "params.a / doc[clicks].value",
"lang" : "painless",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "Variable [clicks] is not defined."
}
}
}
}
],
"caused_by" : {
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
"params.a / doc[clicks].value",
" ^---- HERE"
],
"script" : "params.a / doc[clicks].value",
"lang" : "painless",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "Variable [clicks] is not defined."
}
}
},
"status" : 400
}
然后不知道是不是配置的问题,在elasticsearch.yml里面加上了:
script.stored: true
script.inline: true
script.search: true
script.engine.groovy.stored.aggs: true
script.engine.groovy.inline.search: true
但是重启会报错,
[WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: unknown setting [script.engine.groovy.stored.aggs] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.3.2.jar:6.3.2]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.3.2.jar:6.3.2]
大概长这样,是不是现在不支持了?请问要如何正确使用script呢?
1 个回复
rochy - rochy_he
赞同来自:
其次,,script score 的写法已经变化了,不再是 inline 了