ElasticsearchDSL icon indicating copy to clipboard operation
ElasticsearchDSL copied to clipboard

Missing weight parameter in function score query for certain functions

Open Ekimik opened this issue 4 years ago • 0 comments

Hi, I am using version 7.2.1 of your library and I have just noticed that I cannot add weight attribute when I am adding field value factor function. Is this intentional? I can see $weight parameter in ONGR\ElasticsearchDSL\Query\Compound\FunctionScoreQuery::addDecayFunction method.

Methods

  • ONGR\ElasticsearchDSL\Query\Compound\FunctionScoreQuery::addFieldValueFactorFunction
  • ONGR\ElasticsearchDSL\Query\Compound\FunctionScoreQuery::addRandomFunction
  • ONGR\ElasticsearchDSL\Query\Compound\FunctionScoreQuery::addScriptScoreFunction

on the other hand do not have this parameter.

As far as I know, you can add weight to any function supported by function score query, see documentation

Because scores can be on different scales (for example, between 0 and 1 for decay functions but arbitrary for field_value_factor) and also because sometimes a different impact of functions on the score is desirable, the score of each function can be adjusted with a user defined weight. The weight can be defined per function in the functions array (example above) and is multiplied with the score computed by the respective function.

I have also noticed that there is method ONGR\ElasticsearchDSL\Query\Compound\FunctionScoreQuery::addSimpleFunction, is this the way I should use to add weight?

Ekimik avatar Apr 14 '21 14:04 Ekimik