gpt4 book ai didi

lucene - 执行 custom_score 查询时类型强制转换异常

转载 作者:行者123 更新时间:2023-11-29 02:50:48 26 4
gpt4 key购买 nike

Elasticsearch 版本:0.90.2

我正在尝试让 custom_score 查询正常工作,以便它根据新近度对文档进行评分,但到目前为止我得到的只是一个

ClassCastException[org.elasticsearch.index.fielddata.ScriptDocValues$Longs cannot be cast to java.lang.Integer]

想法是用具有整数类型时间戳的字段索引文档,然后比较它在查询中传递当前时间戳参数。索引整数值怎么变长了?

重现命令如下:

curl -XPUT 'http://localhost:9200/test_longs_problem/'

curl -XPUT 'http://localhost:9200/test_longs_problem/albums/_mapping' -d '
{
"albums" : {
"properties" : {
"date" : {"type" : "integer", "analyzed" : false}
}
}
}'

curl -XPUT 'http://localhost:9200/test_longs_problem/albums/1' -d '
{
"date" : 1376823903
}'

curl -XGET 'http://localhost:9200/test_longs_problem/albums/_search?pretty' -d '{
"query": {
"custom_score": {
"query": {
"match_all": {}
},
"params": {
"now": 1376823903
},
"script": "_score * 0.2 / (3.16 * pow(10, -9) * abs(now - doc[\"date\"]) + 0.05) + 1.0"
}
}
}'

抛出

{
"error" : "SearchPhaseExecutionException[Failed to execute phase [query_fetch], total failure; shardFailures {[NSdeWzwNSIeLtGA1mtLTyA][test_longs_problem][0]: QueryPhaseExecutionException[[test_longs_problem][0]: query[filtered(custom score (ConstantScore(*:*),function=script[_score * 0.2 / (3.16 * pow(10, -9) * abs(now - doc[\"date\"]) + 0.05) + 1.0], params [{_source=org.elasticsearch.search.lookup.SourceLookup@7249d155, now=1376823903, _fields=org.elasticsearch.search.lookup.FieldsLookup@4c4e5e11, _doc=org.elasticsearch.search.lookup.DocLookup@2d01d53a, doc=org.elasticsearch.search.lookup.DocLookup@2d01d53a, _score=1.0}]))->cache(_type:albums)],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: CompileException[[Error: uncomparable values <<1376823903>> and <<org.elasticsearch.index.fielddata.ScriptDocValues$Longs@41983ee7>>]\n[Near : {... _score * 0.2 / (3.16 * pow(10, ....}]\n ^\n[Line: 1, Column: 1]]; nested: RuntimeException[uncomparable values <<1376823903>> and <<org.elasticsearch.index.fielddata.ScriptDocValues$Longs@41983ee7>>]; nested: ClassCastException[org.elasticsearch.index.fielddata.ScriptDocValues$Longs cannot be cast to java.lang.Integer]; }]",
"status" : 500
}

最佳答案

您需要使用.value 属性来获取字段的值。换句话说,您的脚本应如下所示:

"_score * 0.2 / (3.16 * pow(10, -9) * abs(now - doc[\"date\"].value) + 0.05) + 1.0"

关于lucene - 执行 custom_score 查询时类型强制转换异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18333519/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com