Search code examples
datefiltersolrfacet

Solr: Get a hierarchy facets from date


I want to get facets from solar divided by Year and Month (with relative number of element). I tried this query but it doesn't work.

solr/knowledge_base/select?facet.field=creationDate
&facet.date=creationDate
&facet.date.start=NOW-10YEAR
&facet.date.end=NOW
&facet.date.gap=+1MONTH
&facet=on
&facet.mincount=1
&q=*:*
&wt=json

Solution

  • Your facet parameter names are wrong - the name is facet.range, not facet.date. You probably also want to do NOW/MONTH to get the start of the month for your first bucket as well, instead of having your buckets move through the month as time passes.

    So for your actual range parameters:

    &facet.range=creationDate
    &facet.range.start=NOW/MONTH-10YEAR
    &facet.range.end=NOW
    &facet.range.gap=+1MONTH