**大家好,
我试图使用脚本分数应用自定义分数,但我正面临这个问题…非常感谢您的帮助
这是我正在使用的查询。
我的查询是基于Elastic关于script_score的文档,其中包括script_score下的查询。下面是Elastic文档的链接Script_score查询文档* *
{
"from":0,
"size":6,
"query":{
"bool":{
"must":{
"function_score":{
"score_mode":"sum",
"boost_mode":"replace",
"functions":[
{
"weight":0
},
{
"script_score":{
"query":{
"bool":{
"filter":{
"term":{
"title":"jordan"
}
}
}
},
"script":{
"source":"params.termFreq * Math.log10((params.doCount - (params.allDocFreq * params.numDocs/params.maxDocs) + 1) / (params.allDocFreq * params.numDocs/params.maxDocs)) / Math.log10(1 + params.doCount) * 1000 /5",
"params":{
"termFreq":1278,
"titleDocFreq":1274,
"allDocFreq":3630,
"doCount":3909828,
"numDocs":4492778,
"maxDocs":4497180
}
}
}
},
{
"script_score":{
"query":{
"bool":{
"filter":{
"term":{
"title":"faithful"
}
}
}
},
"script":{
"source":"params.termFreq * Math.log10((params.doCount - (params.allDocFreq * params.numDocs/params.maxDocs) + 1) / (params.allDocFreq * params.numDocs/params.maxDocs)) / Math.log10(1 + params.doCount) * 1000 /5",
"params":{
"termFreq":61,
"titleDocFreq":61,
"allDocFreq":391,
"doCount":3909828,
"numDocs":4492778,
"maxDocs":4497180
}
}
}
},
{
"script_score":{
"query":{
"bool":{
"filter":{
"term":{
"title":"return"
}
}
}
},
"script":{
"source":"params.termFreq * Math.log10((params.doCount - (params.allDocFreq * params.numDocs/params.maxDocs) + 1) / (params.allDocFreq * params.numDocs/params.maxDocs)) / Math.log10(1 + params.doCount) * 1000 /5",
"params":{
"termFreq":1857,
"titleDocFreq":1856,
"allDocFreq":5334,
"doCount":3909828,
"numDocs":4492778,
"maxDocs":4497180
}
}
}
},
{
"script_score":{
"query":{
"bool":{
"filter":{
"term":{
"title":"pray"
}
}
}
},
"script":{
"source":"params.termFreq * Math.log10((params.doCount - (params.allDocFreq * params.numDocs/params.maxDocs) + 1) / (params.allDocFreq * params.numDocs/params.maxDocs)) / Math.log10(1 + params.doCount) * 1000 /5",
"params":{
"termFreq":188,
"titleDocFreq":188,
"allDocFreq":421,
"doCount":3909828,
"numDocs":4492778,
"maxDocs":4497180
}
}
}
},
{
"script_score":{
"query":{
"bool":{
"filter":{
"term":{
"title":"mosques"
}
}
}
},
"script":{
"source":"params.termFreq * Math.log10((params.doCount - (params.allDocFreq * params.numDocs/params.maxDocs) + 1) / (params.allDocFreq * params.numDocs/params.maxDocs)) / Math.log10(1 + params.doCount) * 1000 /5",
"params":{
"termFreq":61,
"titleDocFreq":61,
"allDocFreq":182,
"doCount":3909828,
"numDocs":4492778,
"maxDocs":4497180
}
}
}
}
],
"query":{
"match":{
"title":{
"query":"jordan faithful return pray mosques",
"minimum_should_match":2
}
}
}
}
}
}
},
"track_scores":true,
"min_score":38,
"sort":[
{
"unknown_language":{
"order":"asc"
}
},
{
"_score":{
"order":"desc"
},
"release_time":{
"order":"desc"
}
}
]
}
我得到的错误
{
"error":{
"root_cause":[
{
"type":"parsing_exception",
"reason":"script_score query does not support [query]",
"line":1,
"col":156
}
],
"type":"x_content_parse_exception",
"reason":"[1:156] [bool] failed to parse field [must]",
"caused_by":{
"type":"parsing_exception",
"reason":"script_score query does not support [query]",
"line":1,
"col":156
}
},
"status":400
}
filter
在不需要时使用任何评分,在不需要评分时更快的响应,因为弹性不需要计算它
根据错误提示你需要使用must