【发布时间】:2017-04-27 11:53:10
【问题描述】:
我使用弹性搜索的 script_score 通过使用 doc['field_name'] 语法`获取长类型字段的值,而查询操作抛出异常。 查询语法及异常详情如下:
curl -XPOST http://211.159.155.44:9200/iktest/item/_search?pretty -d'
{
"query": {
"function_score": {
"query": {
"match": {
"content": "likaifu"
}
},
"functions": [
{
"gauss": {
"date": {
"offset": "0d",
"scale": "5d"
}
}
},
{
"script_score": {
"script": {
"lang": "expression",
"inline": "doc['score'].value"
}
}
}
],
"score_mode": "multiply",
"boost_mode": "replace"
}
}
}
'
"caused_by" : {
"type" : "query_shard_exception",
"reason" : "script_score: the script could not be loaded",
"index_uuid" : "jVYGC8-jTpCCyZJi-VJtmA",
"index" : "iktest",
"caused_by" : {
"type" : "script_exception",
"reason" : "compile error",
"caused_by" : {
"type" : "parse_exception",
"reason" : "unexpected character '[' on line (1) position (3)",
"caused_by" : {
"type" : "lexer_no_viable_alt_exception",
"reason" : null
}
},
"script_stack" : [
"doc[score].value",
" ^---- HERE"
],
"script" : "doc[score].value",
"lang" : "expression"
}
}
【问题讨论】:
-
尝试研究如何正确转义“inline”行中的单引号:“doc['score'].value”
-
也许像 "inline": "doc[\"score\"].value" 会起作用?
-
@DanielGray 将内联语法更改为 "inline": "doc[\"score\"].value" 成功。非常感谢。
标签: elasticsearch