# How to create buckets for number of occurances

**URL:** <https://discuss.elastic.co/t/how-to-create-buckets-for-number-of-occurances/200763>\
**Category:** Elasticsearch\
**Created:** [September 23, 2019, 9:47pm UTC](https://discuss.elastic.co/t/how-to-create-buckets-for-number-of-occurances/200763 "2019-09-23T21:47:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rwhaley](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rwhaley](https://discuss.elastic.co/u/rwhaley)\
**Post date:** [September 23, 2019, 9:47pm UTC](https://discuss.elastic.co/t/how-to-create-buckets-for-number-of-occurances/200763/1 "2019-09-23T21:47:05Z")

</div>

I am needing to create a query that will show users that have uploaded 'x' number of receipts. I would like to have the receipt counts as defined 'buckets' which would range from, '0' to '10+'. I have tried to utilize the range aggregation but was unable to solve my issue.

The following query gives me the total number of users that submitted receipts, however my next step would be to group those users in the 'buckets' as listed above.

* * *

#Total Users that Submitted  
GET /myreceiptindex/\_search  
{  
"track\_total\_hits": true,  
"size": 0,  
"query": {  
"bool": {  
"must": [  
{  
"match": {  
"moderationOutcome": "Successful"  
}  
},  
{  
"range": {  
"uploadedOn": {  
"lte": "2019-03-31T23:59:59+00:00",  
"gt": "2019-02-01T12:00:00+00:00"  
}  
}  
},  
{  
"range": {  
"purchasedOn": {  
"lte": "2019-03-31T23:59:59+00:00",  
"gt": "2019-02-01T12:00:00+00:00"  
}  
}  
}  
]  
}  
},  
"aggs": {  
"users\_that\_submitted\_receipts": {  
"cardinality": {  
"field": "participant.participantKey"  
}  
}  
}  
}

---

<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:** [October 21, 2019, 9:47pm UTC](https://discuss.elastic.co/t/how-to-create-buckets-for-number-of-occurances/200763/2 "2019-10-21T21:47:09Z")

</div>

Closed on October 21, 2019, 9:47pm UTC

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