Unable to convert DSL argument: Cannot cast java.lang.String to java.util.Date

In Hibernate search 5 I was using this code for date filter and it was working fine

String from = "2022-01-31";
String to ="2022-03-16";
TermRangeQuery.newStringRange(filter.getKey(), from, to, true, true)

When migrating it to hibernate search 6 we have converted code like this but it is giving exception

String from = "2022-01-31";
String to ="2022-03-16";
pf.range().field(filter.getKey()).between(from, to)

Exception
Unable to convert DSL argument: Cannot cast java.lang.String to java.util.Date

Any reason why we are getting this exception??

When we convert string into java.util.Date then it works but we have runtime date format so,How to deal with it?? Also if date has null then??