Solr Facet only on Date excluding time

2019-07-21 21:55发布

问题:

I am trying to do a facet pivot on two fields timestamp and price and here is how my solr query is: http://localhost:8888/solr/collection1/select?q=description%3laptop&wt=json&indent=true&facet=true&facet.pivot=timestamp,price&stats=true&stats.field=price&stats.facet=timestamp

This gives me the result as:

*"timestamp,price":[{
          "field":"timestamp",
          "value":"2015-06-02T07:12:29.044Z",
          "count":50,
          "pivot":[{
              "field":"price",
              "value":389.0,
              "count":9},
            {
              "field":"price",
              "value":388.0,
              "count":4},
            {
              "field":"price",
              "value":300.0.....*

I would like to change the timestamp format from 2015-06-02T07:12:29.044Z to 2015-06-02 when doing the facet so that the results come back as:

*"timestamp,price":[{
          "field":"timestamp",
          "value":"2015-06-02",
          "count":50,
          "pivot":[{
              "field":"price",
              "value":389.0,
              "count":9},
            {
              "field":"price",
              "value":388.0,
              "count":4},
            {
              "field":"price",
              "value":300.0.....*

So it facets by a day instead of multiple times a day. Is this possible?

回答1:

an easy solution (but needs reindexing) is to put the date only value in another field (you can use this update processor for this, or do it on the client side if you prefer), and then facet on that field.