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

this query 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 I have add boosting like

{
  "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
          }
        }
      ]
    }
  }
}

but this give me results only with is_active=1

Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41
kskaradzinski
  • 4,954
  • 10
  • 48
  • 70

1 Answers1

0

Try this:

{
  "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
          }
        }
      ]
    }
  }
}
Andrei Stefan
  • 51,654
  • 6
  • 98
  • 89