Can a Boosting Query be applied to multiple values of a given field?

Hi guys,

Re 5.0 Boosting Queries
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html

I'm interested in the best way to boost scores based on the importance of kinds of text (e.g. titles, comments), etc.

I'm experimenting with a mapping that uses a nested object containing 2 fields: text and weight, and I want to boost scores at query time based on the values of the weight field.

Is this possible with the "boosting" query? From results using the query below, I see that the docs that match the "positive" clause are boosted, but scores for other docs are unchanged. Am I doing something wrong?

{
  "query": {
    "bool": {
      "must": {
        "nested": {
          "path": "content",
          "score_mode": "avg",
          "query":  {
            "bool": {
              "must":
                [
                  {"match": {"content.text": "aid"} }
                ],
              "should": 
                 {"boosting": {
                    "positive": {
                      "term" : {"content.weight": 2}
                    },
                    "negative": {
                      "term" : {"content.weight": 0}
                    },                    
                    "negative_boost": 0.5
                  }
                 }
            }
          }
          }
        }                   
      }
  }  
}

I have documents with weight values of 0,1,2; the only scores affected based on my tests are those with weight 2.

Thanks!

Given your use-case, it might be simpler and more flexible to use script_score. https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-script-score

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.