Your query is malformed. You are using two queries here `nested` and `bool`. Both these queries must be wrapped in either `must`, `should` or `filter` of a bool query. Assuming both the condition are necessary for a match, both these queries should be wrapped in either `must` or `filter` clause of a `bool` query as below:
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "metadata",
"query": {
"bool": {
"should": [
{
"match": {
"metadata.deleted": true
}
}
]
}
}
}
},
{
"must": {
"term": {
"on_behalf_of": "b71457f731d8a6f"
}
}
}
]
}
}
}
Your second `must` clause is not properly located, it must be inside the existing `bool/must` query. You need to rewrite your query to this:
{
"from":0,
"size":15,
"query":{
"bool":{
"must":[
{
"multi_match":{
"query":"books",
"fields":[
"title^20",
"lead^10",
"content"
],
"type":"phrase"
}
},
{
"match":{
"groupid": "599e4b49239cfa0a5a5f189d"
}
}
]
}
},
"sort":[
{
"times":{
"order":"desc"
}
}
]
}