1

Is there some way, that I can remove default boost term from elastic relevance scoring or make it 1(so it does not reflect in scoring). for example,

edit: input query is

GET test_index/_search
{
  "query": {
    "match": {
      "text": "asia pacific"
    }
},"explain": true
}

partial results are

"details" : [
        {
          "value" : 6.5127892,
          "description" : "weight(text:asia in 5417) [PerFieldSimilarity], result of:",
          "details" : [
            {
              "value" : 6.5127892,
              "description" : "score(freq=6.0), product of:",
              "details" : [
                {
                  "value" : 2.2,
                  "description" : "boost",
                  "details" : [ ]
                },
                {
                  "value" : 3.8113363,
                  "description" : "idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:",
                  "details" : [
                    {
                      "value" : 462,
                      "description" : "n, number of documents containing term",
                      "details" : [ ]
                    },
                    {
                      "value" : 20909,
                      "description" : "N, total number of documents with field",
                      "details" : [ ]
                    }
                  ]
                },
                { 
                  "value" : 0.7767246,
                  "description" : "tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:",
                  "details" : [
                    {
                      "value" : 6.0,
                      "description" : "freq, occurrences of term within document",
                      "details" : [ ]
                    },
                    {
                      "value" : 1.2,
                      "description" : "k1, term saturation parameter",
                      "details" : [ ]
                    },
                    {
                      "value" : 0.75,
                      "description" : "b, length normalization parameter",
                      "details" : [ ]
                    },
                    {
                      "value" : 1048.0,
                      "description" : "dl, length of field (approximate)",
                      "details" : [ ]
                    },
                    {
                      "value" : 662.01294,
                      "description" : "avgdl, average length of field",
                      "details" : [ ]
                    }
                  ]
                }
              ]
            }
          ]
        },

This is the explanation of one of the terms in a simple match query. In the above example, I want to remove the boost term of 2.2 or make it equal to 1. please suggest how to do this.

1 Answers1

2

Use bool->filter instead of bool->must in your query. That's precisely what Filter is for.

Joe - GMapsBook.com
  • 15,787
  • 4
  • 23
  • 68
  • I am currently using a simple query like this, `GET test_index/_search { "query": { "match": { "text": "asia pacific" } } } ` which fetches me the results, but if I use, `GET test_index/_search { "query": { "bool": { "filter": { "term": { "text": "asia pacific" } } } } }`, it returns 0 results. Any suggestions on what am I doing wrong here. – divyanshumarwah May 19 '20 at 17:56
  • Term vs match is already answered here: https://stackoverflow.com/a/23151332/8160318 If you want to keep a score of 1, use this: `{"query":{"bool":{"filter":[{"match":{"text":"asia pacific"}}]}}}` – Joe - GMapsBook.com May 19 '20 at 21:03
  • Thanks for the suggestion. But I am trying to make boost as 1, and still, need the BM25 based TF and IDF scores. Using this format of bool->filter->match gives a constant score, that is different from what I am trying to achieve. – divyanshumarwah May 20 '20 at 05:46
  • Oh I misread your question. I think you cannot cherry-pick the scoring parts... You can adjust the final score by a script or by a function score (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html) but you cannot break up the `match` scoring strategy. – Joe - GMapsBook.com May 20 '20 at 07:38