Date_histogram facet with another grouping

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.

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.

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.

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

Best regards.
Marcin Dojwa

2012/4/13 Marcin Dojwa 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.
For more options, visit https://groups.google.com/groups/opt_out.