Adding a negative boost in a multi_match query

Hi everyone,

I just started with Elastic Search I wanted to make some items in the query less relevant, so I am trying to give them a negative boost (make the two items in the must_not sub-query less relevant).

And example of my code:

          query: {
            bool: {
                should: [
                    {
                        multi_match: {
                            query: searchQueryString,
                            fields: ['someType^10', 'someName^4'],
                            type: 'best_fields',
                            operator: 'or',
                            fuzziness: 'AUTO',
                        },
                    },
                    {
                        multi_match: {
                            query: searchQueryString,
                            fields: ['someType^10', 'someName^4'],
                            type: 'phrase',
                            operator: 'or',
                        },
                    },
                ],
              minimum_should_match: '2',
              must_not: [
                  {
                      terms: {
                          type: ['xxxx', 'xxxy'],
                      },
                  },
              ],
              negative_boost: 0.5,
            },
                must: searchCriteria,
            },

I've added the type terms xxxx and xxxy a negative boost, but the response from Elasticsearch is:

message
: 
"x_content_parse_exception" 

When the must_not statement is remove, the code can query Elasticsearch, but when I add this the error above is returned.

              must_not: [
                  {
                      terms: {
                          type: ['xxxx', 'xxxy'],
                      },
                  },
              ],
              negative_boost: 0.5,
            },
                must: searchCriteria,
            },

Did I make a typo of some kind, of is there another way to do this?

{
"query": {
  "bool": {
    "should": [
      {
        "multi_match": {
          "query": "",
          "fields": []
        }
      },
      {
        "multi_match": {
          "query": "",
          "fields": []
        }
      }
    ],
    "minimum_should_match": 1,
    "must_not": [
      {
        "terms": {
          "FIELD": [
            "VALUE1",
            "VALUE2"
          ],
          "boost": 0.5
        }
      }
    ]
  }
}
}

Please try using boost instead if negative_boost. Defaul boost is 1. So if you configure 0.5 it will reduce the boost for specified terms. If it still doesn't solve your problem, you should consider using Boosting query | Elasticsearch Guide [8.8] | Elastic

Yes, this was where I was searching for. Thank you :slightly_smiling_face:

To fast :t_rex: :t_rex: It seems that it will just remote the item from the result, no matter the score

should: [
    {
        multi_match: {
            query: searchQueryString,
            fields: ['xxx^10', 'xxxx^4', 'xxx^4'],
            type: 'best_fields',
            operator: 'or',
            fuzziness: 'AUTO',
        },
    },
    {
        multi_match: {
            query: searchQueryString,
            fields: ['xxx^10', 'xxxx^4', 'xxx^4'],
            type: 'phrase',
            operator: 'or',
        },
    },
],
    minimum_should_match: '1',
    must_not: [
    {
        terms: {
            type: ['item1', 'item2'],
            boost: 0.5,
        },
    },
],

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.