我正在使用Elasticsearch OSS(docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.4
)的官方Docker镜像,似乎根本无法使script_score
正常工作。似乎未启用脚本。
例如,此:
POST http://localhost:9200/address/address/_search
{
"query": {
"function_score": {
"query": {
"match": {
"fullAddress": {
"query": "13 fake",
"operator": "and"
}
}
},
"script_score": {
"lang": "expression",
"source": "doc['flatNumber'].length"
}
}
}
}
给我这个:
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "script_score query does not support [source]",
"line": 13,
"col": 15
}
],
"type": "parsing_exception",
"reason": "script_score query does not support [source]",
"line": 13,
"col": 15
},
"status": 400
}
我尝试启用它:
PUT http://localhost:9200/_cluster/settings
{
"persistent": {
"script.engine.groovy.inline.aggs": "on"
}
}
但无济于事:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "persistent setting [script.engine.groovy.inline.aggs], not recognized"
}
],
"type": "illegal_argument_exception",
"reason": "persistent setting [script.engine.groovy.inline.aggs], not recognized"
},
"status": 400
}
如何让script_score
工作?
答案 0 :(得分:1)
您只是在script
中缺少script_score
部分。像这样修改它,它将起作用:
"script_score": {
"script": {
"lang": "expression",
"source": "doc['flatNumber'].length"
}
}