悟空,拿我的打狗棒来

在script_score使用doc['date']排序出错

Elasticsearch | 作者 hubiao | 发布于2020年01月15日 | 阅读数:744

DSL
"query": {
              "function_score": {
                "script_score": {
                  "script": "_score * doc['date_date_sore'].value.getTimeInMillis()"
                }
              }
            }
 
 
日志
{"error": {

"root_cause": [

{

"type": "script_exception",
"reason": "runtime error",
"script_stack": [

"_score * doc['date_date_sore'].value.getTimeInMillis()"
,
" ^---- HERE"

],
"script": "_score * doc['date_date_sore'].value.getTimeInMillis()",
"lang": "painless"

}

],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [

{

"shard": 0,
"index": "book",
"node": "g8_FSKX_QjWiKudI5I-s7A",
"reason": {

"type": "script_exception",
"reason": "runtime error",
"script_stack": [

"_score * doc['date_date_sore'].value.getTimeInMillis()"
,
" ^---- HERE"

],
"script": "_score * doc['date_date_sore'].value.getTimeInMillis()",
"lang": "painless",
"caused_by": {

"type": "illegal_argument_exception",
"reason": "dynamic method [org.elasticsearch.script.JodaCompatibleZonedDateTime, getTimeInMillis/0] not found"

}

}

}

]

},
"status": 400}
已邀请:

hubiao

赞同来自: tacsklet

已解决
人家已经告诉 是org.elasticsearch.script.JodaCompatibleZonedDateTime, getTimeInMillis没有这个方法,那么顺着这个提示去找它提供 了哪些方法,于是在https://www.elastic.co/guide/e ... eTime  找着了!
解决方法是
 doc['date_date_sore'].value.getTimeInMillis()改为 doc['date_date_sore'].value.getMillis()

要回复问题请先登录注册