2

Solr 8.11 (in SolrCloud mode) returns a 500 error when querying with sort parameter sort=field("RECORD_DATE") asc.

The error message is:

class java.lang.String cannot be cast to class org.apache.lucene.util.BytesRef (java.lang.String is in module java.base of loader 'bootstrap'; org.apache.lucene.util.BytesRef is in unnamed module of loader org.eclipse.jetty.webapp.WebAppClassLoader @7f69d591)

RECORD_DATE is a multivalued field. I don't have problems when using a "simple" field such as score for sorting.

What is strange is that the error only occurs in a multi-shard environment. In a single-shard environment, there is no error!

Juuso Ohtonen
  • 8,826
  • 9
  • 65
  • 98
  • 1
    Does the behavior change if you don't wrap it in `field`? There is generally no need to use a function query for plain sorting if you don't give a value after the `RECORD_DATE` parameter: " its simplest (single argument) form, this function can only be used on single valued fields, and can be called using the name of the field as a string" - you're expected to have a `min`/`max` qualifier behind it to select the corresponding value from the multivalued field (you'll need docvalues, and for efficiency you should resolve min/max when indexing) – MatsLindh Aug 25 '23 at 12:44
  • https://solr.apache.org/guide/solr/latest/query-guide/function-queries.html#field-function – MatsLindh Aug 25 '23 at 12:44
  • @MatsLindh unless I wrap `RECORD_DATE` in `field`, even the single-shard sort stops working – I get _java.lang.UnsupportedOperationException\n\tat org.apache.lucene.queries.function.FunctionValues.doubleVal(FunctionValues.java:50)\n\tat org.apache.lucene.queries.function.ValueSource$ValueSourceComparator.copy(ValueSource.java:417)_ In addition: `field(RECORD_DATE, min)` produces _sort param could not be parsed as a query, and is not a field that exists in the index_. – Juuso Ohtonen Aug 28 '23 at 04:28

0 Answers0