Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeSeries Desc Sort gets skipped with Lucene 10 upgrade #17329

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.CollectorManager;
import org.apache.lucene.search.ConjunctionUtils;
import org.apache.lucene.search.ConstantScoreQuery;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.IndexSearcher;
Expand Down Expand Up @@ -257,7 +258,15 @@ public void search(

@Override
public void search(Query query, Collector collector) throws IOException {
super.search(query, collector);
// TODO : Remove when switching to use the @org.apache.lucene.search.IndexSearcher#search(Query, CollectorManager) variant from
// @org.opensearch.search.query.QueryPhase#searchWithCollector which then calls the overridden
// search(LeafReaderContextPartition[] partitions, Weight weight, Collector collector)
query = collector.scoreMode().needsScores() ? rewrite(query) : rewrite(new ConstantScoreQuery(query));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@msfroh this change make sense to me to restore searchContext.shouldUseTimeSeriesDescSortOptimization() optimization, wdyt?

Weight weight = createWeight(query, collector.scoreMode(), 1);
LeafSlice[] leafSlices = getSlices();
for (LeafSlice leafSlice : leafSlices) {
Copy link
Collaborator

@reta reta Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@expani I think we should get all partitions across all slices and call search only once:

LeafReaderContextPartition[] partitions = Arrays.stream(getSlices()).flatMap(LeafSlice::partitions).toArray();
search(partitions, weight, collector)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can override the logic in getSlices, we could even handle the desc sort use-case more efficiently by returning slices that contain leafcontextpartitions with the higher doc ids and front-load those.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestions @reta @msfroh

I am still facing regression with desc_sort_timestamp and it's variants let me try fixing using these and will update in sometime.

search(leafSlice.partitions, weight, collector);
}
searchContext.bucketCollectorProcessor().processPostCollection(collector);
}

Expand Down
Loading