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"]}]