Query within a query

I’m using parent-child relationship.
Before 2.0.0, the filtered query used to first filter the query and then run the second query. So this code was working

{
"query": {
"filtered": {
"filter": {
"term": {
"kind": "rock"
}
},
"query": {
"has_child": {
"type": "song",
"score_mode": "sum",
"query": {
"match_all": {}
}
}
}
}
}
}

However, now since filtered query is deprecated, I’m trying with the bool query and this one fails

{
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"term": {
"kind": "rock"
}
}
},
"has_child": {
"type": "song",
"score_mode": "sum",
"query": {
"match_all": {}
}
}
}
}

How to write this?

Try this instead:

{
  "query": {
    "bool": {
      "must": [
        {
          "has_child": {
            "type": "song",
            "score_mode": "sum", 
            "query": {
              "match_all": {}
            }
          }
        }
      ],
      "filter": {
        "term": {
          "kind": "rock"
        }
      }
    }
  }
}

Thanks @shaunak. That works!