# Histogram aggregation can start only from divisible by interval value

**URL:** <https://discuss.elastic.co/t/histogram-aggregation-can-start-only-from-divisible-by-interval-value/21346>\
**Category:** Elasticsearch\
**Created:** [December 21, 2014, 7:49pm UTC](https://discuss.elastic.co/t/histogram-aggregation-can-start-only-from-divisible-by-interval-value/21346 "2014-12-21T19:49:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Demetrioca](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/demetrioca/32/856_2.png) [@Demetrioca](https://discuss.elastic.co/u/Demetrioca)\
**Post date:** [December 21, 2014, 7:49pm UTC](https://discuss.elastic.co/t/histogram-aggregation-can-start-only-from-divisible-by-interval-value/21346/1 "2014-12-21T19:49:46Z")

</div>

Here is my code to reproduce this problem:

> <https://gist.github.com/2e3s/9cab65985d932a060704>

  
There is my comment with the result.  
The problem is that I can't make histogram start from the value I want.  
For instance, I've got a set of values _1..11_, I want to start the  
histogram from \*extended\_bounds.min=\*7 and group by _interval=3_. I expect  
to get results _7 (3 docs), 10 (2 docs)_, but actually I get this: _6 (2  
docs), 9 (3 docs)_.  
As you see the histogram goes only by divisible by interval values (it's  
the same if the set is 2..11). There is no related information about this  
behaviour in the ES docs.

Is this a bug? How can I solve that problem and accomplish that what I need?

Thank you in advance.

--  
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/088d249c-e442-4e2d-8c82-8292a97f40ec%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/088d249c-e442-4e2d-8c82-8292a97f40ec%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [December 21, 2014, 9:28pm UTC](https://discuss.elastic.co/t/histogram-aggregation-can-start-only-from-divisible-by-interval-value/21346/2 "2014-12-21T21:28:52Z")

</div>

Hi,

This feature is not supported by the histogram aggregation. Maybe one way  
you could achieve the same thing would be by using a script that subtracts  
1 from your field values?

On Sun, Dec 21, 2014 at 8:49 PM, Demetrioca [2e3s19@gmail.com](mailto:2e3s19@gmail.com) wrote:

> Here is my code to reproduce this problem:  
> [Elasticsearch histogram can start only from divisible by interval value · GitHub](https://gist.github.com/2e3s/9cab65985d932a060704)  
> There is my comment with the result.  
> The problem is that I can't make histogram start from the value I want.  
> For instance, I've got a set of values _1..11_, I want to start the  
> histogram from \*extended\_bounds.min=\*7 and group by _interval=3_. I  
> expect to get results _7 (3 docs), 10 (2 docs)_, but actually I get this: _6  
> (2 docs), 9 (3 docs)_.  
> As you see the histogram goes only by divisible by interval values (it's  
> the same if the set is 2..11). There is no related information about this  
> behaviour in the ES docs.
> 
> Is this a bug? How can I solve that problem and accomplish that what I  
> need?
> 
> Thank you in advance.
> 
> --  
> 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/088d249c-e442-4e2d-8c82-8292a97f40ec%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/088d249c-e442-4e2d-8c82-8292a97f40ec%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/088d249c-e442-4e2d-8c82-8292a97f40ec%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/088d249c-e442-4e2d-8c82-8292a97f40ec%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
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/CAL6Z4j5PGDcACULku7%3DbFLGCcg4sfzjF4nPurVPh-egrOg59AQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5PGDcACULku7%3DbFLGCcg4sfzjF4nPurVPh-egrOg59AQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Demetrioca](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/demetrioca/32/856_2.png) [@Demetrioca](https://discuss.elastic.co/u/Demetrioca)\
**Post date:** [December 22, 2014, 7:22am UTC](https://discuss.elastic.co/t/histogram-aggregation-can-start-only-from-divisible-by-interval-value/21346/3 "2014-12-22T07:22:19Z")

</div>

That's not good, I wonder if it can be improved in the next versions.  
Thanks anyway, it works with \*script \*(added to the github gist):

curl -XPOST "[http://localhost:9200/divisible/divisible/\_search?pretty=true&search\_type=count](http://localhost:9200/divisible/divisible/_search?pretty=true&search_type=count)" -d '  
{  
"query":{  
"range": {"value": {"gte": 7}}  
},  
"aggregations": {  
"rows": {  
"histogram": {  
"field": "value",  
"interval": 3,  
"script": "\_value-1",  
"lang":"groovy",  
"min\_doc\_count": 0,  
"extended\_bounds": { "min": 7 }  
}  
}  
}  
}  
'

The result appears to be expected, I need only add +1 (remainder from the  
start value divided by interval) to the aggregated keys in my code.  
If histogram aggregation would support value transformation for histogram  
aggregation it would even look like the aggregation supports what I need.

On Monday, December 22, 2014 3:29:00 AM UTC+6, Adrien Grand wrote:

> Hi,
> 
> This feature is not supported by the histogram aggregation. Maybe one way  
> you could achieve the same thing would be by using a script that subtracts  
> 1 from your field values?
> 
> On Sun, Dec 21, 2014 at 8:49 PM, Demetrioca \<[2e3...@gmail.com](mailto:2e3...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Here is my code to reproduce this problem:  
> > [Elasticsearch histogram can start only from divisible by interval value · GitHub](https://gist.github.com/2e3s/9cab65985d932a060704)  
> > There is my comment with the result.  
> > The problem is that I can't make histogram start from the value I want.  
> > For instance, I've got a set of values _1..11_, I want to start the  
> > histogram from \*extended\_bounds.min=\*7 and group by _interval=3_. I  
> > expect to get results _7 (3 docs), 10 (2 docs)_, but actually I get  
> > this: _6 (2 docs), 9 (3 docs)_.  
> > As you see the histogram goes only by divisible by interval values (it's  
> > the same if the set is 2..11). There is no related information about this  
> > behaviour in the ES docs.
> > 
> > Is this a bug? How can I solve that problem and accomplish that what I  
> > need?
> > 
> > Thank you in advance.
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/088d249c-e442-4e2d-8c82-8292a97f40ec%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/088d249c-e442-4e2d-8c82-8292a97f40ec%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/088d249c-e442-4e2d-8c82-8292a97f40ec%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/088d249c-e442-4e2d-8c82-8292a97f40ec%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Adrien Grand

--  
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/742f5293-c3c8-47b2-a616-54c80b932250%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/742f5293-c3c8-47b2-a616-54c80b932250%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, 12:42am UTC](https://discuss.elastic.co/t/histogram-aggregation-can-start-only-from-divisible-by-interval-value/21346/4 "2017-07-06T00:42:25Z")

</div>


