0

What does bool query with must and should on same level means ?

I saw the query bellow:

{
  "query": {
    "bool": {
        
     "must": 
        [{
          "match": {
            "content": {
              "reporter": "Ricky"             
            }
          }
        }], 
        
      "should": 
      [{
          "match": {
            "header": {
              "query": "nature"
            }
          }
        }]
      
    }
  }
}
  1. So what does this bool query mean ?
  2. Does should contributes here to the final score (if must query dosn't take any place) ?
Boom
  • 1,145
  • 18
  • 44

1 Answers1

2

must + should is only about search relevance improvement and not just and + or

  1. the above query means: find me all document whose content field contains "ricky" and give a little boost to those documents also having "nature" in their header field.

  2. The query in must MUST be met, i.e. if no document contain "ricky" in their content field, there won't be any match in the result set.

Val
  • 207,596
  • 13
  • 358
  • 360
  • If "should" is only used in these types of queries for boosting the score only, how can one achieve something simple like `(A & B) | C` using these? let's say its number ranges so `(x>=4 & x <=6) | x=2` - which query can give you the potential result set of `2,4,5,6`? `must=A,B` and `should=C` won't work. – Corel Aug 05 '23 at 19:17
  • @Corel please feel free to start a new thread with your question – Val Aug 06 '23 at 16:15
  • Here https://stackoverflow.com/questions/76843879/how-to-write-a-bool-query-of-a-b-c-condition-in-elasticsearch – Corel Aug 06 '23 at 19:55