Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
9.0
-
None
-
New
Description
We have run into this issue while migrating to OpenSearch and making changes to accommodate https://issues.apache.org/jira/browse/LUCENE-10087. It turned out that IndexSortSortedNumericDocValuesRangeQuery unconditionally assumes the usage of the LONG-encoded SortField, as could be seen inside static ValueComparator loadComparator method
@SuppressWarnings("unchecked") FieldComparator<Long> fieldComparator = (FieldComparator<Long>) sortField.getComparator(1, 0); fieldComparator.setTopValue(topValue);
Using the numeric range query (in case of sorted index) with anything but LONG ends up with class cast exception:
> java.lang.ClassCastException: class java.lang.Long cannot be cast to class java.lang.Integer (java.lang.Long and java.lang.Integer are in module java.base of loader 'bootstrap') > at org.apache.lucene.search.comparators.IntComparator.setTopValue(IntComparator.java:29) > at org.apache.lucene.sandbox.search.IndexSortSortedNumericDocValuesRangeQuery.loadComparator(IndexSortSortedNumericDocValuesRangeQuery.java:251) > at org.apache.lucene.sandbox.search.IndexSortSortedNumericDocValuesRangeQuery.getDocIdSetIterator(IndexSortSortedNumericDocValuesRangeQuery.java:206) > at org.apache.lucene.sandbox.search.IndexSortSortedNumericDocValuesRangeQuery$1.scorer(IndexSortSortedNumericDocValuesRangeQuery.java:170)
Simple test case to reproduce (for TestIndexSortSortedNumericDocValuesRangeQuery):
public void testIndexSortDocValuesWithIntRange() throws Exception { Directory dir = newDirectory(); IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random())); Sort indexSort = new Sort(new SortedNumericSortField("field", SortField.Type.INT, false)); iwc.setIndexSort(indexSort); RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc); writer.addDocument(createDocument("field", -80)); DirectoryReader reader = writer.getReader(); IndexSearcher searcher = newSearcher(reader); // Test ranges consisting of one value. assertEquals(1, searcher.count(createQuery("field", -80, -80))); writer.close(); reader.close(); dir.close(); }
The expectation is that IndexSortSortedNumericDocValuesRangeQuery should not fail with class cast but correctly convert the numeric values.
Attachments
Issue Links
- links to