提升查询无法正常工作

Boosting query is not working properly

{
  "sort": [
    {
      "is_active": "asc"
    }
  ],
  "fields": [
    "is_job_seeking", "is_active"
  ],
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "must": {
              "term": {
                "is_job_seeking": 1
              }
            }
          }
        }
      ]
    }
  }
}

这个查询 return me all document which has is_job_seeking=1, and is_active=0 and is_active=1 and that's fine, now when I want to boost score for document which has is_active=1 我已添加 boosting

{
  "sort": [
    {
      "is_active": "asc"
    }
  ],
  "fields": [
    "is_job_seeking", "is_active"
  ],
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "must": {
              "term": {
                "is_job_seeking": 1
              }
            }
          }
        },
        {
          "boosting": {
            "positive": {
              "term": {
                "is_active": 1
              }
            },
            "negative": {
              "term": {
                "is_active": 0
              }
            },
            "negative_boost": 0.3
          }
        }
      ]
    }
  }
}

但这只给我 is_active=1

的结果

试试这个:

{
  "sort": [
    {
      "is_active": "asc"
    }
  ],
  "fields": [
    "is_job_seeking",
    "is_active"
  ],
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "must": {
              "term": {
                "is_job_seeking": 1
              }
            }
          }
        }
      ],
      "should": [
        {
          "boosting": {
            "positive": {
              "term": {
                "is_active": 1
              }
            },
            "negative": {
              "term": {
                "is_active": 0
              }
            },
            "negative_boost": 0.3
          }
        }
      ]
    }
  }
}