# Understanding how nested types are stored in ES

**URL:** <https://discuss.elastic.co/t/understanding-how-nested-types-are-stored-in-es/84634>\
**Category:** Elasticsearch\
**Created:** [May 4, 2017, 10:32pm UTC](https://discuss.elastic.co/t/understanding-how-nested-types-are-stored-in-es/84634 "2017-05-04T22:32:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![arsi](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@arsi](https://discuss.elastic.co/u/arsi)\
**Post date:** [May 4, 2017, 10:32pm UTC](https://discuss.elastic.co/t/understanding-how-nested-types-are-stored-in-es/84634/1 "2017-05-04T22:32:31Z")

</div>

Hi,

Let's say I have a nested type "points":

> "points": [{x: 1, y: 1}, {x:5, y:3},...]

Why is it in that the following query works when I use the term points:

```
GET /mockindex/_search?size=5
{
    "query" : {
        "nested" : {
            "path" : "points",
            "query": {
                "exists" : { "field" : "points" }
            }
        }
    }
}

```

but when I do an aggregation query, using the term "points" doesn't work and I have to do points.x or points.y.

For example this query works:

```
{
    "aggregations" : {
        "nested_layer" : {
            "nested": {
                "path": "points"
            },
            "aggregations" : {
                "result" : {
                    "value_count": {"field": "points.x"}
                }
            }
        }
    }
}

```

and it will return the number of points I have (another way to think of it is that it will return the number of documents I have once Elasticsearch splits each nested type into its own document). However, if I replace points.x with just points, the query doesn't work anymore.

My question is this: if elasticsearch internally represents nested type "points" as "points.x" and "points.y" then how was the first query able to understand when I said "field": "points"? My second question is why am I not able to use "field": "points" in the aggregation query if I was able to use it in the first query? And lastly, is there a way I can write a value\_count query so that it will return the number of documents that contain the field "points" and not the number internally represented documents where "points" are all separated out?

---

<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:** [June 1, 2017, 10:43pm UTC](https://discuss.elastic.co/t/understanding-how-nested-types-are-stored-in-es/84634/2 "2017-06-01T22:43:41Z")

</div>

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