0

I am new to Solr, using Solr 7.3 and I am trying to achieve the following - given a date, I need to retrieve all products which have contracts expiring beyond this date, sorted on the earliest expiring contract, but not considering the already expired contracts. I am not able to get the sort correct. In the below case, product_id "10002023" should have been the last in the list as it has a contract which is expiring last (2021-08-31), ignoring the already expired contract. Any help is greatly appreciated.

http://localhost/solr/catalogue/select?fl=product_id,%20contract_id,%20contract_valid_to&fq=contract_id:[*%20TO%20*]&fq=contract_valid_to:%20[2018-12-12%20TO%20*]&q=*:*&sort=field(contract_valid_to,%20min)%20asc

..."docs":[
{
  "product_id":"10002023",
  "contract_id":["1427",
    "1428"],
  "contract_valid_to":["2018-12-07 15:36:13.0",
    "2021-08-31 15:40:33.0"]},
{
  "product_id":"1012974",
  "contract_id":["867"],
  "contract_valid_to":["2019-05-16 15:58:01.0"]},
{
  "product_id":"1012985",
  "contract_id":["777"],
  "contract_valid_to":["2019-05-19 11:07:50.0"]},
{
  "product_id":"1012975",
  "contract_id":["787"],
  "contract_valid_to":["2019-05-24 12:02:18.0"]},
{
  "product_id":"1012997",
  "contract_id":["831"],
  "contract_valid_to":["2019-05-29 15:37:37.0"]}]

1 Answers1

0

Unfortunately, the definition that you're using for date field is incorrect

<dynamicField name="contract_*" type="string" multiValued="true" indexed="true" stored="true"/>

It is assuming that this is just a plain string, not different from anything else.

Also, regarding your second comment Solr supports dates of only 1 format - YYYY-MM-DDThh:mm:ssZ, so if you want to use date features you would need to do conversion to a proper format and use date type.

Mysterion
  • 9,050
  • 3
  • 30
  • 52