1

I have below elasticsearch query and I want to set the priority order in my query. irrespetive of scoure. eg:

like if I set priority of attack_id > name > description in the match query, then the result should come in this sorted order

attack_id, name, description

and if I set name > attack_id > description

name, attack_id, description

boosting query function query I have tried both of these but don't get success. so I will be very grateful if someone helps me with this.


GET tridant_testing/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "attack_id": "T1592"
          }
        },
        {
          "match": {
            "name": "T1592"
          }
        },
        {
          "match": {
            "description": "T1592"
          }
        }
      ]
    }
  }
}

1 Answers1

0

You can use boost param in match query to boost specific query clause like below:

{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "attack_id": {
              "query": "T1592",
              "boost": 6
            }
          }
        },
        {
          "match": {
            "name": {
              "query": "T1592",
              "boost": 3
            }
          }
        },
        {
          "match": {
            "description": {
              "query": "T1592"
            }
          }
        }
      ]
    }
  }
}

Note: You may need to increase or decrease boost value as per your need.

Sagar Patel
  • 4,993
  • 1
  • 8
  • 19
  • thanks for helping me but the thing is that boost doesn't work successfully in my case because if it finds more match in the description then it increases the score of the description – Abdul Rehman Kaim Khani May 18 '22 at 07:05
  • ok. You can move `description` to `filter` query so it will be not part of `score` calculation. So `attack_id > name > description` this scenario will work as expected. – Sagar Patel May 18 '22 at 07:41