Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to apply facet on date field where result should provide number of records for given date

Tags:

solr

I have a schema in which we are recording device registration time in field devRegDt_dt.

Our service is storing device registration time in this field, and it gets stored in 2015-09-24T14:05:08Z format.

We would like to create query which should provide result as: "2015-09-24" : 5

i.e. "DATE" : <occurances>

Please note that we are ignoring time in this result and only considering date.

Just in case if this is duplicate, please help with related question.

Thanks.

like image 497
navaltiger Avatar asked Dec 15 '15 13:12

navaltiger


1 Answers

You can faceting over date field.
Here is sample query:
http://localhost:8888/solr/lws-map/select?q=*%3A*&wt=json&fl=id&indent=true&facet.range=**facetfield**&facet=true&facet.range.start=NOW-10YEAR&facet.range.end=NOW&facet.range.gap=%2B1MONTH
Above query facet over last 10 years documents and gap is 1 Month. if you want count day wise then change facet.range.gap to XXXDAY
Read more about solr date format at solr wiki.

like image 127
Rahul Sharma Avatar answered Nov 08 '22 07:11

Rahul Sharma