Use Query Bool with Query Nested

Is possible use query > bool together with query > nested?

I have two types of queries, each one returns the results.
Query > Bool

{
    "query":{
        "bool":{
            "must":[
                {
                    "term":{
                        "account": 14492
                    }
                },
                {
                    "term":{
                        "customer": 12345
                    }
                }
            ]
        }
        
    }
}

Query > Nested

{
  "query": {
    "nested": {
       "path": "customfield_open.content",
       "query": {
         "bool": {
           "must": [
             {
               "match": {
                 "customfield_open.content.id": 8914
               }
             },
             {
               "match": {
                 "customfield_open.content.value": "RS"
               }
             }
          ]
        }
      }
    }
  }
}

Merged Querys:

{
    "query":{
        "bool":{
            "must":[
                {
                    "term":{
                        "id":14492
                    }
                },
                {
                    "term":{
                        "customer": 12345
                    }
                }
            ]
        },
        "nested":{
            "path":"customfield_open.content",
            "query":{
                "bool":{
                    "must":[
                        {
                            "match":{
                                "customfield_open.content.id":8914
                            }
                        },
                        {
                            "match":{
                                "customfield_open.content.value":"RS"
                            }
                        }
                    ]
                }
            }
        }
    }
}

Error:

{
    "error": {
        "root_cause": [
            {
                "type": "parsing_exception",
                "reason": "[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
                "line": 17,
                "col": 9
            }
        ],
        "type": "parsing_exception",
        "reason": "[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
        "line": 17,
        "col": 9
    },
    "status": 400
}

Solution:

{
    "query":{
        "bool":{
            "must":[
                {
                    "term":{
                        "id":14492
                    }
                },
                {
                    "term":{
                        "customer": 12345
                    }
                },
                {
                    "nested":{
                        "path":"customfield_open.content",
                        "query":{
                            "bool":{
                                "must":[
                                    {
                                        "match":{
                                            "customfield_open.content.id":8914
                                        }
                                    },
                                    {
                                        "match":{
                                            "customfield_open.content.value":"RS"
                                        }
                                    }
                                ]
                            }
                        }
                    }
                }
            ]
        }
    }
}

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