elasticsearch priorities search result in match query, composite bool query

439 Views Asked by At

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

There are 1 best solutions below

2
Sagar Patel On

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.