# Can I control buckets based on ranges of values?

**URL:** https://discuss.elastic.co/t/can-i-control-buckets-based-on-ranges-of-values/69099
**Category:** Elasticsearch
**Created:** [December 15, 2016, 2:01am UTC](https://discuss.elastic.co/t/can-i-control-buckets-based-on-ranges-of-values/69099 "2016-12-15T02:01:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Berin\_Loritsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/berin_loritsch/32/13895_2.png) [@Berin\_Loritsch](https://discuss.elastic.co/u/Berin_Loritsch)
#### Post date: [December 15, 2016, 2:01am UTC](https://discuss.elastic.co/t/can-i-control-buckets-based-on-ranges-of-values/69099/1 "2016-12-15T02:01:01Z")

</div>

I'm using ElasticSearch 2.4.x, and I've been through the documents and couldn't find anything that addresses the need I have. I'm trying to provide a faceted search facility on my website with counts for the documents that would potentially match the new criteria. Most of what I want is pretty straightforward and the documentation was very helpful. However, I have one facet that's giving me a bit of trouble.

I have a document called "Teachings" that can reference 0..n "Devotional" documents. I have a field "numberOfDevotionals" that has a count of the devotionals that reference that teaching. It's great for providing more detailed summary information in the listing. However, for my aggregation I just want 2 buckets: "0" and "1 or more" for this stat.

I have a query like this:

\</\>  
POST [http://localhost:9200/my-index/teachings/\_search?pretty](http://localhost:9200/my-index/teachings/_search?pretty)  
{  
"size": 3,  
"sort": [{ "endDate": { "order": "desc" } }],  
"query": {  
"constant\_score": {  
"filter": {  
"bool": {  
"must": [  
{  
"term": { "releasableTo": "Member" }  
}  
]  
}  
}  
}  
},  
"aggs": {  
"teachers": {  
"terms": { "field": "[teacher.id](http://teacher.id)", "size": 500 }  
},  
"audio": {  
"terms": { "field": "hasAudio" }  
},  
"transcript": {  
"terms": { "field": "hasTranscript" }  
},  
"landmark": {  
"terms": { "field": "isLandmark" }  
},  
"devotionals": {  
"terms": { "field": "numberOfDevotionals", "size": 100 }  
}  
}  
}  
\</\>

For the "devotionals" aggregation, I want to control the resolution of the buckets. Right now I get different counts (separate buckets for 0-10) so I would have to count up all the buckets that has a key greater than "0". I would rather this be a bucket for "0" and a second bucket for all the rest.

---

<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: [January 12, 2017, 2:01am UTC](https://discuss.elastic.co/t/can-i-control-buckets-based-on-ranges-of-values/69099/2 "2017-01-12T02:01:52Z")

</div>

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