boosting查询

positive部分: 查询返回的查询结果分值不变
negative部分: 查询的结果分值会被降低
negative_boost部分: 设置negative中要降低的分值, 相关性算分降低的程度将由 negative_boost 参数决定,其取值范围为:[0.0, 1.0]

优点: 里面的两个查询都会有结果返回,其中一个分值就是你设置的分值

注意:如果是设有bool的must_not的话,那降低的那部分就没有结果返回

  1. POST books/_search
  2. {
  3. "query": {
  4. "boosting": {
  5. "positive": {
  6. "term": {
  7. "name": {
  8. "value": "linux"
  9. }
  10. }
  11. },
  12. "negative": {
  13. "term": {
  14. "name": {
  15. "value": "programming"
  16. }
  17. }
  18. },
  19. "negative_boost": 0.5
  20. }
  21. }
  22. }

如上示例,我们查询书名中含有 “linux” 的文档,并且想让含有 “programming” 字样的文档的相关性降低一半。在 negative 块中匹配的文档,其相关性算分为:在 positive 中匹配时的算分 * negative_boost

bool对评分的影响

image.png

boost值

参数boost的含义

  • 当boost > 1, 打分的相关度提升
  • 当0 < boost < 1, 打分的权重降低
  • 当 boost < 0, 贡献负分
    1. GET /book/_search
    2. {
    3. "query": {
    4. "range": {
    5. "price": {
    6. "gte": 10,
    7. "lte": 200,
    8. "boost": 2.0
    9. }
    10. }
    11. }
    12. }