ruby-on-railselasticsearchelasticsearch-ruby

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',
  }
}

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.

Here is a part of the explain :

"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:",
[...]

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.

My question is :

How can I set a max possible score for a query ?

Or, even better, can I set a range of score for my query ?

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.

I tried this :

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.


Solution

  • 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