Combining multi_match with boosting

If I understand what you want correct, then you want to only return documents that match the multi_match query but rank documents which don't have any value for field2 highest. In which case you need to have your multi_match query as a must clause (since a document must match this criteria to be returned) and the boosting query as a should clause (since you want documents without a field2 field to rank higher). If so, then try the following:

{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "keyword1 keyword2",
            "type": "best_fields",
            "fields": [
              "field1^3",
              "field2"
            ],
            "tie_breaker": 1
          }
        }
      ],
      "should": [
        {
          "boosting": {
            "negative": {
              "constant_score": {
                "filter": {
                  "missing": {
                    "field": "field2"
                  }
                }
              }
            },
            "negative_boost": 0.2
          }
        }
      ]
    }
  }
}
1 Like