How can I multiply the score of two queries together in Elasticsearch?

前端 未结 2 1696
傲寒
傲寒 2021-01-06 03:41

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 l

2条回答
  •  难免孤独
    2021-01-06 04:39

    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.

提交回复
热议问题