简体   繁体   中英

Elastic search: negative boost for term query

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.

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 (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM