2
votes

At the moment I'm using queries like the following with positive boosting of a term.

    "query": {
        "bool" : {
            "must" : {
                "term" : { "title" : {value :"word", boost: 2.0}}
            }
         }
      }

This type of query is described here. I would like to know if it is possible to use negative boosting of term just like the above, but instead of 2.0 a -2.0. So like this:

     "query": {
        "bool" : {
            "must" : {
                "term" : { "title" : {value :"word", boost: -2.0}}
            }
         }
      }

I couldn't find any documentation on it. It only tells the default value for boost is 1.0. And all examples use positive boosting. There is however some kind of negative boost ( described here), but that is boosting queries instead of terms.

1

1 Answers

0
votes

The best way is to try it out ;-) If you'd get a search exception or something you'll know negative boosts are not allowed. But if you try you'll see that it's not the case and negative boosts are perfectly valid and impact the scores.

As you saw, you can also use boosting_query with a negative_boost which will demote results that match a given query (e.g. those documents having "title": "word"). Watch out, though, than when using this query the negative_boost value must be a "positive" number as it will already be negated within the source code.