想根据文档中的多个字段进行排序,使用script score报错,No such property: w1 for class: 0d34f35ce7dcd19d5942f7f52352cfbb6627c6d0"
1、 文档结构,其中w1-w5都在[0-10]的范围内
curl -XPUT 'http://localhost:9200/stars/star/1' -d '{
"user" : "test",
"title" : "明星1",
"w1" : 10,
"w2" : 1,
"w3": 5,
"w4": 3,
"w5": 8
}'
2,检索请求,分别设置w1-w5的权重,然后综合排序,请求如下
curl -XGET 'http://localhost:9202/stars/star/_search' -d '{
"query": {
"function_score": {
"query": {
"match": {
"title": "明星"
}
},
"script_score": {
"script":"doc['w1'].value * w1_factor + doc['w2'].value * w2_factor + doc['w3'].value * w3_factor + doc['w4'].value * w4_factor + doc['w5'].value * w5_factor",
"params" : {
"w1_factor" : 90,
"w2_factor" : 90,
"w3_factor" : 90,
"w4_factor" : 80,
"w5_ctr" : 0.10
}
}
}
}
}'
3.返回错误结果,No such property: w1 for class: 0d34f35ce7dcd19d5942f7f52352cfbb6627c6d0"
{
"took":19,
"timed_out":false,
"_shards":{
"total":5,
"successful":4,
"failed":1,
"failures":[
{
"shard":3,
"index":"stars",
"node":"9eUXBp57SqaDWwUS_pCK2A",
"reason":{
"type":"script_exception",
"reason":"failed to run inline script [doc[w1].value * w1_factor + doc[w2_factor].value * w2_factor + doc[w3].value * w3_factor + doc[w4_factor].value * w4_factor + doc[w5].value * w5_factor] using lang [groovy]",
"caused_by":{
"type":"missing_property_exception",
"reason":"No such property: w1 for class: 0d34f35ce7dcd19d5942f7f52352cfbb6627c6d0"
}
}
}
]
},
"hits":{
"total":0,
"max_score":null,
"hits":{
}
}
}
1、 文档结构,其中w1-w5都在[0-10]的范围内
curl -XPUT 'http://localhost:9200/stars/star/1' -d '{
"user" : "test",
"title" : "明星1",
"w1" : 10,
"w2" : 1,
"w3": 5,
"w4": 3,
"w5": 8
}'
2,检索请求,分别设置w1-w5的权重,然后综合排序,请求如下
curl -XGET 'http://localhost:9202/stars/star/_search' -d '{
"query": {
"function_score": {
"query": {
"match": {
"title": "明星"
}
},
"script_score": {
"script":"doc['w1'].value * w1_factor + doc['w2'].value * w2_factor + doc['w3'].value * w3_factor + doc['w4'].value * w4_factor + doc['w5'].value * w5_factor",
"params" : {
"w1_factor" : 90,
"w2_factor" : 90,
"w3_factor" : 90,
"w4_factor" : 80,
"w5_ctr" : 0.10
}
}
}
}
}'
3.返回错误结果,No such property: w1 for class: 0d34f35ce7dcd19d5942f7f52352cfbb6627c6d0"
{
"took":19,
"timed_out":false,
"_shards":{
"total":5,
"successful":4,
"failed":1,
"failures":[
{
"shard":3,
"index":"stars",
"node":"9eUXBp57SqaDWwUS_pCK2A",
"reason":{
"type":"script_exception",
"reason":"failed to run inline script [doc[w1].value * w1_factor + doc[w2_factor].value * w2_factor + doc[w3].value * w3_factor + doc[w4_factor].value * w4_factor + doc[w5].value * w5_factor] using lang [groovy]",
"caused_by":{
"type":"missing_property_exception",
"reason":"No such property: w1 for class: 0d34f35ce7dcd19d5942f7f52352cfbb6627c6d0"
}
}
}
]
},
"hits":{
"total":0,
"max_score":null,
"hits":{
}
}
}
2 个回复
zpzkit
赞同来自:
zpzkit
赞同来自:
我的es版本是2.1.2有点旧的版本了,在写script的时候是
注意doc取值是通过单引号取值的,后来改成了这样:
这个可能是es内部对脚本语言的符号解析问题。