# Is there a way to use a facet so that it creates a histogram on every X occurrences in a sequence?

**URL:** <https://discuss.elastic.co/t/is-there-a-way-to-use-a-facet-so-that-it-creates-a-histogram-on-every-x-occurrences-in-a-sequence/7556>\
**Category:** Elasticsearch\
**Created:** [May 3, 2012, 10:09pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-use-a-facet-so-that-it-creates-a-histogram-on-every-x-occurrences-in-a-sequence/7556 "2012-05-03T22:09:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![redCashion](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/redcashion/32/2895_2.png) [@redCashion](https://discuss.elastic.co/u/redCashion)\
**Post date:** [May 3, 2012, 10:09pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-use-a-facet-so-that-it-creates-a-histogram-on-every-x-occurrences-in-a-sequence/7556/1 "2012-05-03T22:09:00Z")

</div>

I'm not seeing how this would be done, but is it possible to have a facet that instead of using date\_interval, uses an interval to give the stats on every X number of occurrences? I have tried doing it like:

"value\_field": "date",  
"key\_field": "net",  
"interval": 1000

But it returns the histogram as groupings of net being in 1000 (ie a bucket for all nets between -1000 and 0, etc).

If I reverse the key\_field and value\_field I get the entire dataset back.

---

<div class="post-metadata">

**Author:** ![redCashion](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/redcashion/32/2895_2.png) [@redCashion](https://discuss.elastic.co/u/redCashion)\
**Post date:** [May 3, 2012, 10:19pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-use-a-facet-so-that-it-creates-a-histogram-on-every-x-occurrences-in-a-sequence/7556/2 "2012-05-03T22:19:11Z")

</div>

As an example, if net was a sequence of numbers ordered by date like:

1,2,3,4,5,6,7  
and I set the interval to 2, I would like to get back a histogram like:

count: 2  
value: 3,

count: 2,  
value: 7,

count: 2,  
value: 11,

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 4, 2012, 1:42pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-use-a-facet-so-that-it-creates-a-histogram-on-every-x-occurrences-in-a-sequence/7556/3 "2012-05-04T13:42:42Z")

</div>

Still cryptic..., I am not sure I understand, but won't histogram facet  
with interval set to 2 on net will do it for you?

On Fri, May 4, 2012 at 1:19 AM, redCashion [xperts@gmail.com](mailto:xperts@gmail.com) wrote:

> As an example, if net was a sequence of numbers ordered by date like:
> 
> 1,2,3,4,5,6,7  
> and I set the interval to 2, I would like to get back a histogram like:
> 
> count: 2  
> value: 3,
> 
> count: 2,  
> value: 7,
> 
> count: 2,  
> value: 11,
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Is-there-a-way-to-use-a-facet-so-that-it-creates-a-histogram-on-every-X-occurrences-in-a-sequence-tp3960603p3960626.html](http://elasticsearch-users.115913.n3.nabble.com/Is-there-a-way-to-use-a-facet-so-that-it-creates-a-histogram-on-every-X-occurrences-in-a-sequence-tp3960603p3960626.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Chris\_Conley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_conley/32/2732_2.png) [@Chris\_Conley](https://discuss.elastic.co/u/Chris_Conley)\
**Post date:** [September 7, 2012, 6:51pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-use-a-facet-so-that-it-creates-a-histogram-on-every-x-occurrences-in-a-sequence/7556/4 "2012-09-07T18:51:22Z")

</div>

Shay, I have a similar need and I believe you're correct with setting an  
interval of 2 in Jeremy's case.

Is there a way to accomplish the same thing but with out a field like  
"net"? (ex: facet on groups of 100 ordered by date)

Or do I need to always maintain a "counter" field like Jeremy's "net" field?

Thanks!  
Chris

On Friday, May 4, 2012 9:42:42 AM UTC-4, kimchy wrote:

> Still cryptic..., I am not sure I understand, but won't histogram facet  
> with interval set to 2 on net will do it for you?
> 
> On Fri, May 4, 2012 at 1:19 AM, redCashion \<[xpe...@gmail.com](mailto:xpe...@gmail.com) \<javascript:\>
> 
> > wrote:
> 
> > As an example, if net was a sequence of numbers ordered by date like:
> > 
> > 1,2,3,4,5,6,7  
> > and I set the interval to 2, I would like to get back a histogram like:
> > 
> > count: 2  
> > value: 3,
> > 
> > count: 2,  
> > value: 7,
> > 
> > count: 2,  
> > value: 11,
> > 
> > --  
> > View this message in context:  
> > [http://elasticsearch-users.115913.n3.nabble.com/Is-there-a-way-to-use-a-facet-so-that-it-creates-a-histogram-on-every-X-occurrences-in-a-sequence-tp3960603p3960626.html](http://elasticsearch-users.115913.n3.nabble.com/Is-there-a-way-to-use-a-facet-so-that-it-creates-a-histogram-on-every-X-occurrences-in-a-sequence-tp3960603p3960626.html)  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--

---

<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/is-there-a-way-to-use-a-facet-so-that-it-creates-a-histogram-on-every-x-occurrences-in-a-sequence/7556/5 "2017-07-06T03:13:39Z")

</div>


