Query to fetch Document if certain nested document does not exists

Hi,

I am new to elastic search and got stuck in a scenario. I have document mapping as below:

    {
        "mappings": {
            "customer": {
                "properties": {
                    "customerEmails": {
                        "type": "nested",
                        "properties": {
                            "address": {
                                "type": "text"
                            },
                            "type": {
                                "type": "text"
                            }
                        }
                    }
                }
            }
        }
    }

Type field in customerEmails object could be Home, Work, and Mobile. I want a query to fetch those document where no email address exists with type Mobile.

GET indexname/_search
{
 "query": {
   "nested": {
     "path": "customer.customerEmails",
     "query": {
       "bool": {
         "must_not": [
           {
             "exists": {
               "field": "address"
             }
           }
         ],
         "must": [
           {
             "term": {
               "customer.customerEmails.type.keyword": {
                 "value": "Mobile"
               }
             }
           }
         ]
       }
     },
     "inner_hits": {
       "name": "customerEmailsFetchResult"
     }
   }
 }
}

Thanks for reply. The query seems to me logically perfect. But it somehow do not bring any result when I hit it in Kibana dev tool not even a single document. I have multiple document that should meeting the query criteria.

you can try one condition at a time and see which part causes this