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

**URL:** <https://discuss.elastic.co/t/field-exist-query-to-check-nested-type-field-exists-for-a-doc/292152>\
**Category:** Elasticsearch\
**Created:** [December 16, 2021, 12:40pm UTC](https://discuss.elastic.co/t/field-exist-query-to-check-nested-type-field-exists-for-a-doc/292152 "2021-12-16T12:40:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudheesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sudheesh/32/99073_2.png) [@sudheesh](https://discuss.elastic.co/u/sudheesh)\
**Post date:** [December 16, 2021, 12:40pm UTC](https://discuss.elastic.co/t/field-exist-query-to-check-nested-type-field-exists-for-a-doc/292152/1 "2021-12-16T12:40:23Z")

</div>

This is the template for my index

```auto
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**

```auto
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

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

```

```auto
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

```auto
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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 13, 2022, 12:41pm UTC](https://discuss.elastic.co/t/field-exist-query-to-check-nested-type-field-exists-for-a-doc/292152/2 "2022-01-13T12:41:14Z")

</div>

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