# Count facet range in nested?

**URL:** <https://discuss.elastic.co/t/count-facet-range-in-nested/11419>\
**Category:** Elasticsearch\
**Created:** [April 2, 2013, 6:32pm UTC](https://discuss.elastic.co/t/count-facet-range-in-nested/11419 "2013-04-02T18:32:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![softtech\_Wonder](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@softtech\_Wonder](https://discuss.elastic.co/u/softtech_Wonder)\
**Post date:** [April 2, 2013, 6:32pm UTC](https://discuss.elastic.co/t/count-facet-range-in-nested/11419/1 "2013-04-02T18:32:59Z")

</div>

My data  
user1 = {"friends": array(idFriend1, idFriend2, idFriend3,  
idFriend4,...,idFriendN)}  
user2 = {"friends": array(idFriend1, idFriend2, idFriend3,  
idFriend4,...,idFriendN)}  
userN= {"friends": array(.....)}  
I want to list and count all persons who have 0-10 friends, 11-100 friends,  
etc...  
I had tried many ways to manage but it isn't successfully. Who knows how to  
solve this problem, please guide me. Thanks a lot!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![softtech\_Wonder](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@softtech\_Wonder](https://discuss.elastic.co/u/softtech_Wonder)\
**Post date:** [April 4, 2013, 7:52pm UTC](https://discuss.elastic.co/t/count-facet-range-in-nested/11419/2 "2013-04-04T19:52:57Z")

</div>

Please help me, or give me a hint!

Vào 01:32:59 UTC+7 Thứ tư, ngày 03 tháng tư năm 2013, softtech Wonder đã  
viết:

> My data  
> user1 = {"friends": array(idFriend1, idFriend2, idFriend3,  
> idFriend4,...,idFriendN)}  
> user2 = {"friends": array(idFriend1, idFriend2, idFriend3,  
> idFriend4,...,idFriendN)}  
> userN= {"friends": array(.....)}  
> I want to list and count all persons who have 0-10 friends, 11-100  
> friends, etc...  
> I had tried many ways to manage but it isn't successfully. Who knows how  
> to solve this problem, please guide me. Thanks a lot!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 4, 2013, 7:59pm UTC](https://discuss.elastic.co/t/count-facet-range-in-nested/11419/3 "2013-04-04T19:59:50Z")

</div>

IMHO, you should handle that on client side. I mean before indexing document, just add a numberOfFriends field set to the array size.  
Then, you will be able to ask for a RangeFacet on that field.

## HTH

David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 4 avr. 2013 à 21:52, softtech Wonder [wondersofttech@gmail.com](mailto:wondersofttech@gmail.com) a écrit :

> Please help me, or give me a hint!
> 
> Vào 01:32:59 UTC+7 Thứ tư, ngày 03 tháng tư năm 2013, softtech Wonder đã viết:  
> My data  
> user1 = {"friends": array(idFriend1, idFriend2, idFriend3, idFriend4,...,idFriendN)}  
> user2 = {"friends": array(idFriend1, idFriend2, idFriend3, idFriend4,...,idFriendN)}  
> userN= {"friends": array(.....)}  
> I want to list and count all persons who have 0-10 friends, 11-100 friends, etc...  
> I had tried many ways to manage but it isn't successfully. Who knows how to solve this problem, please guide me. Thanks a lot!
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mattweber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattweber/32/44940_2.png) [@mattweber](https://discuss.elastic.co/u/mattweber)\
**Post date:** [April 4, 2013, 8:01pm UTC](https://discuss.elastic.co/t/count-facet-range-in-nested/11419/4 "2013-04-04T20:01:43Z")

</div>

Or range facet with a script that returns the size of the friends array...  
Storing it like David said is better for performance.

On Thursday, April 4, 2013, David Pilato wrote:

> IMHO, you should handle that on client side. I mean before indexing  
> document, just add a numberOfFriends field set to the array size.  
> Then, you will be able to ask for a RangeFacet on that field.
> 
> ## HTH
> 
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 4 avr. 2013 à 21:52, softtech Wonder \<[wondersofttech@gmail.com](mailto:wondersofttech@gmail.com)\<javascript:\_e({}, 'cvml', 'wondersofttech@gmail.com');\>\>  
> a écrit :
> 
> Please help me, or give me a hint!
> 
> Vào 01:32:59 UTC+7 Thứ tư, ngày 03 tháng tư năm 2013, softtech Wonder đã  
> viết:
> 
> > My data  
> > user1 = {"friends": array(idFriend1, idFriend2, idFriend3,  
> > idFriend4,...,idFriendN)}  
> > user2 = {"friends": array(idFriend1, idFriend2, idFriend3,  
> > idFriend4,...,idFriendN)}  
> > userN= {"friends": array(.....)}  
> > I want to list and count all persons who have 0-10 friends, 11-100  
> > friends, etc...  
> > I had tried many ways to manage but it isn't successfully. Who knows how  
> > to solve this problem, please guide me. Thanks a lot!
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com) \<javascript:\_e({},  
> 'cvml', 'elasticsearch+unsubscribe@googlegroups.com');\>.  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com) \<javascript:\_e({},  
> 'cvml', 'elasticsearch%2Bunsubscribe@googlegroups.com');\>.  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Thanks,  
Matt Weber

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_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:** [July 6, 2017, 2:42am UTC](https://discuss.elastic.co/t/count-facet-range-in-nested/11419/5 "2017-07-06T02:42:44Z")

</div>


