我使用script_score
自定义得分:
GET /customer/_search
{
"query": {
"function_score": {
"query": {
"match": {
"name": "Mark"
}
},
"script_score": {
"script": {
"lang": "painless",
"file": "test"
}
}
}
}
}
我设置了"file": "test"
,并将test.groovy
文件放在config/scripts
目录中,但是出现了以下错误:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "[script] unknown field [file], parser not found"
}
],
"type": "illegal_argument_exception",
"reason": "[script] unknown field [file], parser not found"
},
"status": 400
}
[script] unknown field [file], parser not found
!为什么?我需要安装一些插件吗?
Elasticsearch版本:6.2.3
已安装插件:无
JVM版本:1.8.0_181
操作系统版本:Ubuntu Linux 4.4.0-124-通用
答案 0 :(得分:1)
File scripts have been removed在ES 6.0中,您现在应该改为使用stored scripts。
您可以轻松migrate your Groovy script to Painless。
首先,存储您的脚本:
POST _scripts/test
{
"script": {
"lang": "painless",
"source": "Math.log(_score * 2)"
}
}
然后在查询中使用它:
GET /customer/_search
{
"query": {
"function_score": {
"query": {
"match": {
"name": "Mark"
}
},
"script_score": {
"script": {
"id": "test"
}
}
}
}
}