# Search on count of nested (child) documents

**URL:** <https://discuss.elastic.co/t/search-on-count-of-nested-child-documents/25087>\
**Category:** Elasticsearch\
**Created:** [July 7, 2015, 8:49pm UTC](https://discuss.elastic.co/t/search-on-count-of-nested-child-documents/25087 "2015-07-07T20:49:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zach](https://avatars.discourse-cdn.com/v4/letter/z/51bf81/32.png) [@Zach](https://discuss.elastic.co/u/Zach)\
**Post date:** [July 7, 2015, 8:49pm UTC](https://discuss.elastic.co/t/search-on-count-of-nested-child-documents/25087/1 "2015-07-07T20:49:00Z")

</div>

Can I search for all documents with \> _N_ children?

Let's say I've got a social network with the following mapping:

```
{
  “users” : {
    “properties” : {
      “username” : {“type” : “string”, "index": "not_analyzed”},
      “full_name” : {“type” : “string”},
      “friends” : {
        “type” : “nested”,
        “properties” : {
          “username” : {“type” : “string”, "index": "not_analyzed”},
          “date_friended” : {“type” : “date”},
        }
      }
    } 
  }
}

```

Can I search for all users with \> 5 friends? As of right now, I'm maintaining a separate count of the children in the parent document.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![slitt987](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@slitt987](https://discuss.elastic.co/u/slitt987)\
**Post date:** [March 2, 2017, 7:14pm UTC](https://discuss.elastic.co/t/search-on-count-of-nested-child-documents/25087/2 "2017-03-02T19:14:01Z")

</div>

@Zach - Any luck regarding this? I have roughly the same question and found this old ask. Curious how to bump it back up to see if someone has any new ideas with ES 5.

---

<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:02pm UTC](https://discuss.elastic.co/t/search-on-count-of-nested-child-documents/25087/3 "2017-07-05T22:02:40Z")

</div>


