diff --git a/docs/changelog/135767.yaml b/docs/changelog/135767.yaml new file mode 100644 index 0000000000000..6843a029665e6 --- /dev/null +++ b/docs/changelog/135767.yaml @@ -0,0 +1,5 @@ +pr: 135767 +summary: Pass fix size instead of `maxPageSize` to `LuceneTopNOperator` scorer +area: ES|QL +type: bug +issues: [] diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneTopNSourceOperator.java b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneTopNSourceOperator.java index 6e1162b167889..bf357035905a1 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneTopNSourceOperator.java +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneTopNSourceOperator.java @@ -123,6 +123,9 @@ public String describe() { } } + // We use the same value as the INITIAL_INTERVAL from CancellableBulkScorer + private static final int NUM_DOCS_INTERVAL = 1 << 12; + private final CircuitBreaker breaker; private final List> sorts; private final long estimatedPerRowSortSize; @@ -213,7 +216,7 @@ private Page collect() throws IOException { perShardCollector = newPerShardCollector(scorer.shardContext(), sorts, needsScore, limit); } var leafCollector = perShardCollector.getLeafCollector(scorer.leafReaderContext()); - scorer.scoreNextRange(leafCollector, scorer.leafReaderContext().reader().getLiveDocs(), maxPageSize); + scorer.scoreNextRange(leafCollector, scorer.leafReaderContext().reader().getLiveDocs(), NUM_DOCS_INTERVAL); } catch (CollectionTerminatedException cte) { // Lucene terminated early the collection (doing topN for an index that's sorted and the topN uses the same sorting) scorer.markAsDone(); diff --git a/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/EsqlActionTaskIT.java b/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/EsqlActionTaskIT.java index 5d3586b689832..0c075dfeaa3f6 100644 --- a/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/EsqlActionTaskIT.java +++ b/x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/action/EsqlActionTaskIT.java @@ -511,7 +511,7 @@ public void testTaskContentsForTopNQuery() throws Exception { try { getTasksStarting(); logger.info("unblocking script"); - scriptPermits.release(pageSize()); + scriptPermits.release(numberOfDocs() + pageSize()); List tasks = getTasksRunning(); String sortStatus = """ [{"pause_me":{"order":"asc","missing":"_last","unmapped_type":"long"}}]""";