Field exist query to check nested type field exists for a doc

This is the template for my index

PUT employee_index
{
  "mappings":{
    "properties": {
    "role": {
      "type": "text"
    },
    "Employee": {
            "type": "nested",
            "properties": {
              "employeeId": {
                "type": "keyword"
              },
              "name": {
                "type": "text"
              },
              "Contact": {
                "type": "nested",
                "properties": {
                  "Email": {
                    "type": "nested",
                    "properties": {
                      "emailId": {
                        "type": "text"
                      }
                    }
                  },
                  "Address": {
                    "type": "nested",
                    "properties": {
                      "city": {
                        "type": "text"
                      },
                      "stateName": {
                        "type": "text"
                      },
                      "zip": {
                        "type": "text"
                      }
                    }
                  }
                }
              }
            }
          }
  }
}
}

I indexed a doc to the above index as follow

POST employee_index/_doc
{
  "role":"example",
  "Employee":[
    {
      "employeeId":"emp1",
      "name":"john",
      "Contact":[{
        "Email":[{
          "emailId":"john@gmail.com"
        }],
        "Address":[{
          "city":"los angeles",
          "stateName":"California",
          "zip":"12345"
        }]
      }]
    }]
}

My use case is, i want to get all the docs which have contact object.I tried below querys to get the doc, but i got zero results

GET employee_index/_search
{
  "query": {
   "nested":{
      "path":"Employee",
      "query":{
         "bool":{
            "must":[
               {
                  "exists":{
                     "field":"Employee.Contact"
                  }
               }
            ]
         }
      }
   }
}
}
GET employee_index/_search
{
  "query": {
   "nested":{
      "path":"Employee",
      "query":{
        "exists":{
          "field":"Employee.Contact"
        }
      }
    }
  }
}

And i know that if i try field exist query as below then it will work

GET employee_index/_search
{
  "query": {
   "nested":{
      "path":"Employee.Contact.Email",
      "query":{
        "exists":{
          "field":"Employee.Contact.Email.emailId"
        }
      }
    }
  }
}

But i want to check whether Contact object is exist, not Employee.Contact.Email.emailId

Thank you

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