# Unexpected exists behaviour on field which value is an array of nested objects

**URL:** <https://discuss.elastic.co/t/unexpected-exists-behaviour-on-field-which-value-is-an-array-of-nested-objects/51784>\
**Category:** Elasticsearch\
**Created:** [June 3, 2016, 9:47am UTC](https://discuss.elastic.co/t/unexpected-exists-behaviour-on-field-which-value-is-an-array-of-nested-objects/51784 "2016-06-03T09:47:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alef](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@alef](https://discuss.elastic.co/u/alef)\
**Post date:** [June 3, 2016, 9:47am UTC](https://discuss.elastic.co/t/unexpected-exists-behaviour-on-field-which-value-is-an-array-of-nested-objects/51784/1 "2016-06-03T09:47:26Z")

</div>

Hello everyone,

The behaviour of the `exists` query in the following example puzzles me:

```auto
PUT i
{
  "mappings": {
    "t": {
      "properties": {
        "foo": {
          "type": "nested",
          "properties": {
            "bar": {
              "type": "long"
            }
          }
        }
      }
    }
  }
}

PUT i/t/1
{
  "foo": [
    {
      "bar": 1
    }
  ]
}

POST i/_refresh

GET i/t/_search
{
  "query": {
    "exists": {
      "field": "foo"
    }
  }
}

```

The search returns 0 results, while I expected it to return document `i/t/1`.

Is it the expected behaviour?  
If so, I'd appreciate a pointer to the documentation explaining why this is the case.

Thanks in advance,

Alexis F.

N.B.: I ran this example on Elasticsearch 2.3.3.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [June 3, 2016, 10:11am UTC](https://discuss.elastic.co/t/unexpected-exists-behaviour-on-field-which-value-is-an-array-of-nested-objects/51784/2 "2016-06-03T10:11:54Z")

</div>

> [@alef](#):
>
> Is it the expected behaviour?

Yes.

> [@alef](#):
>
> I'd appreciate a pointer to the documentation explaining why this is the case

From [1] - _" the term-level queries operate on the exact terms that are stored in the inverted index."_

"foo" does not exist as an indexed (and therefore searchable) primitive term. It is essentially exists only as a naming prefix for the leaf-level primitive field "foo.bar".

[1] [Term level queries | Java API [2.3] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-api/2.3/java-term-level-queries.html)

---

<div class="post-metadata">

**Author:** ![alef](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@alef](https://discuss.elastic.co/u/alef)\
**Post date:** [June 3, 2016, 11:49am UTC](https://discuss.elastic.co/t/unexpected-exists-behaviour-on-field-which-value-is-an-array-of-nested-objects/51784/3 "2016-06-03T11:49:41Z")

</div>

Thank you Mark for your quick reply and pointer!

---

<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:** [July 5, 2017, 10:46pm UTC](https://discuss.elastic.co/t/unexpected-exists-behaviour-on-field-which-value-is-an-array-of-nested-objects/51784/4 "2017-07-05T22:46:25Z")

</div>


