有没有一种方法可以设置查询的分数范围(或最高分数) [英] Is there a way to set a score range (or a max score) for a query
问题描述
我有一个非常简单的查询:
I have a very simple query :
match: {
field => {
boost: 4,
query: term,
fuzziness: 'AUTO',
}
}
由其他几个(约10个)组成,其中大多数使用constant_score查询.问题在于,按照特定的条件,我的查询得分过高,无法取消所有其他查询结果.
Composed with several (about 10) others queries most of them using constant_score. The problem is that on specific terms, my query has a too big score that cancel all others queries results.
这是解释的一部分:
"details" => [
[0] {
"value" => 63.656006,
"description" => "sum of:",
"details" => [
[0] {
"value" => 63.656006,
"description" => "weight(title.de:kandinsky in 1694239) [PerFieldSimilarity], result of:",
"details" => [
[0] {
"value" => 63.656006,
"description" => "score(doc=1694239,freq=1.0 = termFreq=1.0\n), product of:",
"details" => [
[0] {
"value" => 4.0,
"description" => "boost",
"details" => []
},
[1] {
"value" => 11.3820715,
"description" => "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
[...]
您已经看到了,由于IDF,我的分数为11.38.我的其他查询(分数在1到3之间)完全没有用.
Has you can see, I have a score of 11.38 due to the IDF. My others queries (with scores between 1 and 3) are totally useless.
我的问题是:
如何设置查询的最高可能得分?
How can I set a max possible score for a query ?
或者更好,我可以为查询设置分数范围吗?
Or, even better, can I set a range of score for my query ?
我想避免对该字段进行constant_score查询,我需要一些TF/IDF和该字段的得分概念,但强度不高.
I would like to avoid a constant_score query for this field, I need a few TF/IDF and score notion for this field but not that strong.
我尝试过这个:
function_score: {
query: { match: {
field => term,
}},
score_mode: :avg,
script_score: {
script: {
inline: "4 * (1 + Math.log(2 + _score))",
}
},
}
更好,但在某些情况下仍然可以取得很高的分数.
It's better but it can still perform a very high score on certain cases.
推荐答案
您是否尝试过使用功能得分查询?这是相同的链接 https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html
have u tried using Function score query ? Here is the link for the same https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html
这篇关于有没有一种方法可以设置查询的分数范围(或最高分数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!