Question about must query

Course: < Elastic Certified Engineer Exam>
Version: <8.1>
Question:
What is the difference between following two queries?

1:

{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "star",
            "fields": [
              "original_title^2",
              "overview",
              "tagline"
            ]
          },
          "range": {
            "vote_average": {
              "gt": 7
            }
          }
        }
      ]
    }
  }
} 

2:

{
  "query": {
    "bool": {
      "must": 
        {
          "multi_match": {
            "query": "star",
            "fields": [
              "original_title^2",
              "overview",
              "tagline"
            ]
          },
          "range": {
            "vote_average": {
              "gt": 7
            }
          }
        }
    }
  }
} 

Does I need the array brackets or not?

Hello,

You are just missing the after the must array, so: the first has must: , the second is missing the

Yes, you need the array brackets. The "must" command is allowed to have one argument without using the array notation, i.e. square brackets, . However, if you want to use more than one argument you need square brackets. Here you do have more than one - multi_match and range. Thus, #1 will work but #2 will not work.

The range must be within it's own 'clause' within the array so I don't believe either of those will work.

This works:

{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "star",
            "fields": [
              "original_title^2",
              "overview",
              "tagline"
            ]
          }
        },
        {
          "range": {
            "vote_average": {
              "gt": 7
            }
          }
        }
      ]
    }
  }
}

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