# Range facet without knowing bucket sizes

**URL:** https://discuss.elastic.co/t/range-facet-without-knowing-bucket-sizes/8980
**Category:** Elasticsearch
**Created:** [September 11, 2012, 2:49am UTC](https://discuss.elastic.co/t/range-facet-without-knowing-bucket-sizes/8980 "2012-09-11T02:49:14Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Jack\_Markarian](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Jack\_Markarian](https://discuss.elastic.co/u/Jack_Markarian)
#### Post date: [September 11, 2012, 2:49am UTC](https://discuss.elastic.co/t/range-facet-without-knowing-bucket-sizes/8980/1 "2012-09-11T02:49:14Z")

</div>

Hey all,  
is there a good way to be able to run a range facet with X number of  
buckets, but not specifying the size of each bucket? Currently, I am doing  
a statistical facet, and then doing some math with the mean and std  
deviation to construct the buckets, and then running a range facet.. but  
this is not desirable since it requires 2 queries.. any thoughts?

For reference:  
[http://www.elasticsearch.org/guide/reference/api/search/facets/range-facet.html](http://www.elasticsearch.org/guide/reference/api/search/facets/range-facet.html)

--

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [September 11, 2012, 8:56pm UTC](https://discuss.elastic.co/t/range-facet-without-knowing-bucket-sizes/8980/2 "2012-09-11T20:56:03Z")

</div>

I also have the same requirement and have not been able to solve it  
with the existing tools in Elasticsearch.

My approach works well in my system since the range of values is  
constant. Given the historical data, I break the overall range down  
into dozens of sub-ranges which I make into range facets. I then  
assemble these facets into a pre-defined number of buckets on the  
client side. Not very efficient, but it works. A custom collector  
could be used, but I did not want to have to support it with every new  
Elasticsearch release.

Cheers,

Ivan

On Mon, Sep 10, 2012 at 7:49 PM, jackM [markarianhj@gmail.com](mailto:markarianhj@gmail.com) wrote:

> Hey all,  
> is there a good way to be able to run a range facet with X number of  
> buckets, but not specifying the size of each bucket? Currently, I am doing  
> a statistical facet, and then doing some math with the mean and std  
> deviation to construct the buckets, and then running a range facet.. but  
> this is not desirable since it requires 2 queries.. any thoughts?
> 
> For reference:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/facets/range-facet.html)
> 
> --

--

---

<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, 3:13am UTC](https://discuss.elastic.co/t/range-facet-without-knowing-bucket-sizes/8980/3 "2017-07-06T03:13:07Z")

</div>


