# Exists query problem

**URL:** <https://discuss.elastic.co/t/exists-query-problem/298037>\
**Category:** Elasticsearch\
**Created:** [February 23, 2022, 1:09pm UTC](https://discuss.elastic.co/t/exists-query-problem/298037 "2022-02-23T13:09:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Busra\_Duygu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/busra_duygu/32/90462_2.png) [@Busra\_Duygu](https://discuss.elastic.co/u/Busra_Duygu)\
**Post date:** [February 23, 2022, 1:09pm UTC](https://discuss.elastic.co/t/exists-query-problem/298037/1 "2022-02-23T13:09:33Z")

</div>

Hello friends, I need your help on a subject. There is a field with a nested type in an index and another field with a string type in this field. Any record has this field, but I would be very happy if you could help me to get count 0 when I query with exists.When I try it for any other nested field it works but not for one.

**my index mapping:**

```auto
 "MyFieldName1" : {
          "type" : "nested",
          "properties" : {
            "MyFieldName2" : {
              "type" : "keyword"
            },
            "MyFieldName3" : {
              "type" : "float"
            }
          }
        },

```

**My exists query:**

```auto
GET myindexname/_count
{
  "query": {
    "nested": {
      "path": "MyFieldName1",
      "query": {
        "exists": {
          "field": "MyFieldName1.MyFieldName2"
        }
      }
    }
  }
}

Result:
{
  "count" : 0,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  }
}

```

but I'm sure there is a document with this field. Any ideas would be very helpful, thanks in advance.🤗

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [February 23, 2022, 2:45pm UTC](https://discuss.elastic.co/t/exists-query-problem/298037/2 "2022-02-23T14:45:37Z")

</div>

I suppose there is typo or somet trivial error.  
Your problem was not reproduced in my environment 7.16.3.

```auto
PUT test_nested
{
  "mappings": {
    "properties": {
      "MyFieldName1" : {
        "type" : "nested",
        "properties" : {
          "MyFieldName2" : {
            "type" : "keyword"
          },
          "MyFieldName3" : {
            "type" : "float"
          }
        }
      }
    }
  }
}

POST test_nested/_doc
{
  "MyFieldName1":{
    "MyFieldName2": "foo",
    "MyFieldName3": 1.5
  }
}

GET test_nested/_search

GET test_nested/_count
{
  "query": {
    "nested": {
      "path": "MyFieldName1",
      "query": {
        "exists": {
          "field": "MyFieldName1.MyFieldName2"
        }
      }
    }
  }
}

```

```auto
{
  "count" : 1,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  }
}

```

The count was 1.

---

<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:** [March 23, 2022, 2:45pm UTC](https://discuss.elastic.co/t/exists-query-problem/298037/3 "2022-03-23T14:45:40Z")

</div>

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