From f9d08c18647ceda398e634bb2a43d78fadb535b4 Mon Sep 17 00:00:00 2001 From: Ioana Tagirta Date: Thu, 2 Oct 2025 20:35:36 +0200 Subject: [PATCH] ES|QL: Pass fixed size instead of maxPageSize to LuceneTopNOperator scorer (#135767) --- docs/changelog/135767.yaml | 5 +++++ .../compute/lucene/LuceneTopNSourceOperator.java | 5 ++++- .../elasticsearch/xpack/esql/action/EsqlActionTaskIT.java | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 docs/changelog/135767.yaml 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 ea0df8f56372c..34ba112acd79d 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 @@ -119,6 +119,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; @@ -202,7 +205,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 bf94a875fe2c4..ad6056cc9cd63 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"}}]""";