如何在Elasticsearch中将两个查询的分数相加在一起? [英] How can I multiply the score of two queries together in Elasticsearch?
问题描述
在Solr中,我可以使用查询
函数查询返回查询的数值分数,我可以在 bf的上下文中使用用户
参数类似 bf = product(query('cat'),query('dog'))
将两个相关性分数相乘。 p>
Elasticsearch具有通常更灵活的搜索API,但我无法弄清楚我将如何完成同样的壮举。我可以在function_query的script_function中使用 _score
,但我只能使用主查询的 _score
。如何整合另一个查询的分数?您可以使用脚本编写一个TF * IDF评分函数,如何将分数乘以一起?
function_score 查询。这样(忽略Lucene的查询和长度规范化):
script:tf = _index [field] [term] .tf(); idf =(1 + log(_index.numDocs()/(_index [field] [term] .df()+ 1))); return sqrt(tf)* pow(idf,2) b $ b
您将使用猫和狗的功能结果的产品,并将其添加到您的原始查询分数。
以下是完整的查询 gist 。
In Solr I can use the query
function query to return a numerical score for a query and I can user that in the context of a bf
parameter something like bf=product(query('cat'),query('dog'))
to multiply two relevance scores together.
Elasticsearch has search API that is generally more flexible to work with, but I can't figure out how I would accomplish the same feat. I can use _score
in a script_function of a function_query but I can only user the _score
of the main query. How can I incorporate the score of another query? How can I multiply the scores together?
You could script a TF*IDF scoring function using a function_score
query. Something like this (ignoring Lucene's query and length normalization):
"script": "tf = _index[field][term].tf(); idf = (1 + log ( _index.numDocs() / (_index[field][term].df() + 1))); return sqrt(tf) * pow(idf,2)"
You'd take the product of those function results for 'cat' and 'dog' and add them to your original query score.
Here's the full query gist.
这篇关于如何在Elasticsearch中将两个查询的分数相加在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!