# Aggregate doc\_counts of matched nested objects

**URL:** <https://discuss.elastic.co/t/aggregate-doc-counts-of-matched-nested-objects/35227>\
**Category:** Elasticsearch\
**Created:** [November 21, 2015, 5:42pm UTC](https://discuss.elastic.co/t/aggregate-doc-counts-of-matched-nested-objects/35227 "2015-11-21T17:42:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![john83](https://avatars.discourse-cdn.com/v4/letter/j/a88e4f/32.png) [@john83](https://discuss.elastic.co/u/john83)\
**Post date:** [November 21, 2015, 5:42pm UTC](https://discuss.elastic.co/t/aggregate-doc-counts-of-matched-nested-objects/35227/1 "2015-11-21T17:42:50Z")

</div>

I would like to know how many of my documents have X number of matching nested objects.

This is a similar document to what I'm working with. In reality they have many more attributes:

`{ "title": "Example", "events": [{ "id": "event-1", "timestamp": "2015-10-10T10:10:10" }, { "id": "event-2", "timestamp": "2015-11-11T11:11:11" }] }`

I have millions of documents and each document have 0-50 (could be even more) nested objects (events).

I'm filtering such that I only want the nested objects that fall within a certain date range. I then would like to know how many of the docs have 1, 2, 3, 4.. (and so on) matching nested objects. Is this possible? I'm using ES 2.0.

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [November 23, 2015, 3:36pm UTC](https://discuss.elastic.co/t/aggregate-doc-counts-of-matched-nested-objects/35227/2 "2015-11-23T15:36:16Z")

</div>

Unfortunately I don't think this is something that can be done.

---

<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, 11:36pm UTC](https://discuss.elastic.co/t/aggregate-doc-counts-of-matched-nested-objects/35227/3 "2017-07-05T23:36:33Z")

</div>


