# \[Aggregation\] Be able to count number of item in a sub-collection

**URL:** <https://discuss.elastic.co/t/aggregation-be-able-to-count-number-of-item-in-a-sub-collection/18359>\
**Category:** Elasticsearch\
**Created:** [June 26, 2014, 11:40pm UTC](https://discuss.elastic.co/t/aggregation-be-able-to-count-number-of-item-in-a-sub-collection/18359 "2014-06-26T23:40:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregoire\_Pineau](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregoire_pineau/32/1455_2.png) [@Gregoire\_Pineau](https://discuss.elastic.co/u/Gregoire_Pineau)\
**Post date:** [June 26, 2014, 11:40pm UTC](https://discuss.elastic.co/t/aggregation-be-able-to-count-number-of-item-in-a-sub-collection/18359/1 "2014-06-26T23:40:43Z")

</div>

Hello

I have the following data

[  
{  
"id": 1,  
"collection": [  
{  
"key": "val1"  
},  
{  
"key": "val2"  
},  
{  
"key": "val3"  
}  
]  
},  
{  
"id": 2,  
"collection": [  
{  
"key": "val1"  
},  
{  
"key": "val2"  
}  
]  
}  
]

And I would like to be able to get a repartition of the number of items  
into the  
“collection” key. For example, With my sample, I expect something like:

- 1 documents has 3 items
- 1 document has 2 items

And then, after getting this king of information, I would like to be able to  
query ES to ask something like “give me all document that have 2 items  
under the  
collection property”.

I dig into the documentation, test lot of things with sens, but nothing  
give me the expected result.

So I have few questions:

- Is it possible?
- If yes, where can I find the doc?
- If no, is it because I did not understand ES correctly?

Thanks 😉  
​

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c5973012-9388-44c1-823c-dbc0828ff353%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c5973012-9388-44c1-823c-dbc0828ff353%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Timber](https://avatars.discourse-cdn.com/v4/letter/t/5daacb/32.png) [@Timber](https://discuss.elastic.co/u/Timber)\
**Post date:** [June 27, 2014, 6:40am UTC](https://discuss.elastic.co/t/aggregation-be-able-to-count-number-of-item-in-a-sub-collection/18359/2 "2014-06-27T06:40:48Z")

</div>

Could you not add a count of items in the collection at index time? In this case you could filter on this value.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1cb1b906-1ba2-4099-bd3c-76163e27f196%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1cb1b906-1ba2-4099-bd3c-76163e27f196%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Gregoire\_Pineau](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregoire_pineau/32/1455_2.png) [@Gregoire\_Pineau](https://discuss.elastic.co/u/Gregoire_Pineau)\
**Post date:** [June 27, 2014, 8:25am UTC](https://discuss.elastic.co/t/aggregation-be-able-to-count-number-of-item-in-a-sub-collection/18359/3 "2014-06-27T08:25:22Z")

</div>

Yes and no 😉 Because I would like to be able to also filter node in the  
collection. And then cound.  
Actually, the collection contains orders, and I want to be able to know how  
many paid order I get for a user.

On Friday, June 27, 2014 8:40:49 AM UTC+2, Timber wrote:

> Could you not add a count of items in the collection at index time? In  
> this case you could filter on this value.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/8a2b4608-a54a-4c76-813a-e6a2d810c697%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8a2b4608-a54a-4c76-813a-e6a2d810c697%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:19am UTC](https://discuss.elastic.co/t/aggregation-be-able-to-count-number-of-item-in-a-sub-collection/18359/4 "2017-07-06T01:19:20Z")

</div>

Closed on July 6, 2017, 1:19am UTC


