# Date\_histogram facet with another grouping

**URL:** <https://discuss.elastic.co/t/date-histogram-facet-with-another-grouping/7318>\
**Category:** Elasticsearch\
**Created:** [April 12, 2012, 9:43pm UTC](https://discuss.elastic.co/t/date-histogram-facet-with-another-grouping/7318 "2012-04-12T21:43:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcin\_Dojwa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcin_dojwa/32/2307_2.png) [@Marcin\_Dojwa](https://discuss.elastic.co/u/Marcin_Dojwa)\
**Post date:** [April 12, 2012, 9:43pm UTC](https://discuss.elastic.co/t/date-histogram-facet-with-another-grouping/7318/1 "2012-04-12T21:43:16Z")

</div>

Hi,

Is it possible to group on any other field using histogram\_facet, something  
like date\_histogram\_terms facet? For example, I want to get results grouped  
by date and other term, so the result could look like this (abstract  
format):  
2010-01-01, term1, 21  
2010-01-01, term2, 13  
2010-01-02, term1, 1  
2010-01-02, term2, 2  
2010-01-03, term1, 11  
2010-01-03, term2, 0

If it is not possible, I guess the only way to get this is to get as many  
histogram facets as we have distinct terms right (in this example 2  
histogram facets, one for term1 and 1 for term2)?

Thanks for help  
Best regards.

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [April 12, 2012, 10:42pm UTC](https://discuss.elastic.co/t/date-histogram-facet-with-another-grouping/7318/2 "2012-04-12T22:42:02Z")

</div>

If your index is not very large, you can use script field for that:

```
"facets": {
    "test_facet":{
        "terms":{
            "script" : 

```

"doc.timestamp.date.toString(org.elasticsearch.common.joda.time.format.DateTimeFormat.forPattern("YYYY-MM-dd"))

- ", " + doc.term.value"  
}  
}  
}

If your index is large, it might be better to create another field that  
would contain date and term together.

On Thursday, April 12, 2012 5:43:16 PM UTC-4, Marcin Dojwa wrote:

> Hi,
> 
> Is it possible to group on any other field using histogram\_facet,  
> something like date\_histogram\_terms facet? For example, I want to get  
> results grouped by date and other term, so the result could look like this  
> (abstract format):  
> 2010-01-01, term1, 21  
> 2010-01-01, term2, 13  
> 2010-01-02, term1, 1  
> 2010-01-02, term2, 2  
> 2010-01-03, term1, 11  
> 2010-01-03, term2, 0
> 
> If it is not possible, I guess the only way to get this is to get as many  
> histogram facets as we have distinct terms right (in this example 2  
> histogram facets, one for term1 and 1 for term2)?
> 
> Thanks for help  
> Best regards.

---

<div class="post-metadata">

**Author:** ![Marcin\_Dojwa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcin_dojwa/32/2307_2.png) [@Marcin\_Dojwa](https://discuss.elastic.co/u/Marcin_Dojwa)\
**Post date:** [April 13, 2012, 6:06am UTC](https://discuss.elastic.co/t/date-histogram-facet-with-another-grouping/7318/3 "2012-04-13T06:06:15Z")

</div>

Thanks. I have to check the timing of this script because I use timezones  
at request time, so I have to keep datetime separately.

Thanks for help

W dniu piątek, 13 kwietnia 2012 użytkownik Igor Motov napisał:

> If your index is not very large, you can use script field for that:
> 
> ```
> "facets": {
> "test_facet":{
> "terms":{
> "script" :
> 
> ```
> 
> "doc.timestamp.date.toString(org.elasticsearch.common.joda.time.format.DateTimeFormat.forPattern("YYYY-MM-dd"))
> 
> - ", " + doc.term.value"  
> }  
> }  
> }
> 
> If your index is large, it might be better to create another field that  
> would contain date and term together.
> 
> On Thursday, April 12, 2012 5:43:16 PM UTC-4, Marcin Dojwa wrote:
> 
> > Hi,
> > 
> > Is it possible to group on any other field using histogram\_facet,  
> > something like date\_histogram\_terms facet? For example, I want to get  
> > results grouped by date and other term, so the result could look like this  
> > (abstract format):  
> > 2010-01-01, term1, 21  
> > 2010-01-01, term2, 13  
> > 2010-01-02, term1, 1  
> > 2010-01-02, term2, 2  
> > 2010-01-03, term1, 11  
> > 2010-01-03, term2, 0
> > 
> > If it is not possible, I guess the only way to get this is to get as many  
> > histogram facets as we have distinct terms right (in this example 2  
> > histogram facets, one for term1 and 1 for term2)?
> > 
> > Thanks for help  
> > Best regards.

---

<div class="post-metadata">

**Author:** ![Marcin\_Dojwa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcin_dojwa/32/2307_2.png) [@Marcin\_Dojwa](https://discuss.elastic.co/u/Marcin_Dojwa)\
**Post date:** [February 2, 2013, 6:36pm UTC](https://discuss.elastic.co/t/date-histogram-facet-with-another-grouping/7318/4 "2013-02-02T18:36:36Z")

</div>

For everyone who looks for the solution. There is a plugin elasticfacets  
that can do what I described. It's here:  
[https://github.com/bleskes/elasticfacets](https://github.com/bleskes/elasticfacets)

Best regards.  
Marcin Dojwa

2012/4/13 Marcin Dojwa [m.dojwa@livechatinc.com](mailto:m.dojwa@livechatinc.com)

> Thanks. I have to check the timing of this script because I use timezones  
> at request time, so I have to keep datetime separately.
> 
> Thanks for help
> 
> W dniu piątek, 13 kwietnia 2012 użytkownik Igor Motov napisał:
> 
> If your index is not very large, you can use script field for that:
> 
> > ```
> > "facets": {
> > "test_facet":{
> > "terms":{
> > "script" :
> > 
> > ```
> > 
> > "doc.timestamp.date.toString(org.elasticsearch.common.joda.time.format.DateTimeFormat.forPattern("YYYY-MM-dd"))
> > 
> > - ", " + doc.term.value"  
> > }  
> > }  
> > }
> > 
> > If your index is large, it might be better to create another field that  
> > would contain date and term together.
> > 
> > On Thursday, April 12, 2012 5:43:16 PM UTC-4, Marcin Dojwa wrote:
> > 
> > > Hi,
> > > 
> > > Is it possible to group on any other field using histogram\_facet,  
> > > something like date\_histogram\_terms facet? For example, I want to get  
> > > results grouped by date and other term, so the result could look like this  
> > > (abstract format):  
> > > 2010-01-01, term1, 21  
> > > 2010-01-01, term2, 13  
> > > 2010-01-02, term1, 1  
> > > 2010-01-02, term2, 2  
> > > 2010-01-03, term1, 11  
> > > 2010-01-03, term2, 0
> > > 
> > > If it is not possible, I guess the only way to get this is to get as  
> > > many histogram facets as we have distinct terms right (in this example 2  
> > > histogram facets, one for term1 and 1 for term2)?
> > > 
> > > Thanks for help  
> > > Best regards.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:53am UTC](https://discuss.elastic.co/t/date-histogram-facet-with-another-grouping/7318/5 "2017-07-06T02:53:20Z")

</div>


