Skip to content

ES|QL - LuceneTopNSourceOperator data partition strategy uses ContextIndexSearcher slicing#143133

Merged
carlosdelest merged 38 commits intoelastic:mainfrom
carlosdelest:enhancement/esql-topn-data-partition-strategy
Mar 1, 2026
Merged

ES|QL - LuceneTopNSourceOperator data partition strategy uses ContextIndexSearcher slicing#143133
carlosdelest merged 38 commits intoelastic:mainfrom
carlosdelest:enhancement/esql-topn-data-partition-strategy

Conversation

@carlosdelest
Copy link
Member

@carlosdelest carlosdelest commented Feb 26, 2026

Related #141770

#142128 used high speed partitioning for LuceneTopNSourceOperator. That improved p90 timing but worsened p50 timing, and was reverted in #142453.

Analyzing the Lucene query execution differences, it was clear that ESQL used more slices than the DSL. An excessive number of slices was harming the average use case.

The SEGMENT data partitioning strategy used the Lucene IndexSearcher.slices() static method for calculating the slices. This is not what the DSL does, as it uses the ContextIndexSearcher that in turn overrides some of the default Lucene behavior.

This PR modifies the SEGMENT strategy by using the IndexSearcher that it receives as an instance to calculate the slices via the getSlices() method, instead of using the static IndexSearcher method from Lucene.

This is consistent with the DSL and provides an upper limit on the number of slices created based on the available search threads available.

@carlosdelest carlosdelest added >enhancement Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch :Search Relevance/ES|QL Search functionality in ES|QL labels Feb 26, 2026
@elasticsearchmachine
Copy link
Collaborator

Hi @carlosdelest, I've created a changelog YAML for you.

@carlosdelest carlosdelest added auto-backport Automatically create backport pull requests when merged v9.2.0 v9.3.0 and removed auto-backport Automatically create backport pull requests when merged v9.2.0 labels Feb 26, 2026
@carlosdelest carlosdelest marked this pull request as draft February 26, 2026 18:35
@elasticsearchmachine
Copy link
Collaborator

Hi @carlosdelest, I've updated the changelog YAML for you.

carlosdelest and others added 7 commits February 27, 2026 08:24
…-data-partition-strategy

# Conflicts:
#	x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/query/LuceneSourceOperator.java
…-partition-strategy' into enhancement/esql-topn-data-partition-strategy
…-partition-strategy' into enhancement/esql-topn-data-partition-strategy
Copy link
Contributor

@jimczi jimczi left a comment

Choose a reason for hiding this comment

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

LGTM

@carlosdelest carlosdelest marked this pull request as ready for review February 27, 2026 11:23
Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Contributor

@ioanatia ioanatia left a comment

Choose a reason for hiding this comment

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

looks good, I was wondering if we can further simplify some checks now that the node level materialization is enabled on release builds


private static AutoStrategy topNAutoStrategy() {
return unusedLimit -> {
if (EsqlCapabilities.Cap.ENABLE_REDUCE_NODE_LATE_MATERIALIZATION.isEnabled()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like this capability is always enabled - see #142834
do we still need this check - or could we always use LuceneSliceQueue.PartitioningStrategy.SEGMENT

Copy link
Member Author

Choose a reason for hiding this comment

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

Ooooh, that happened!

Thanks for checking, I removed the cap check in 15cd5aa

private static Matcher<String> expectedAutoPartition(String index, String idxPartition) {
private static Matcher<String> expectedAutoPartition(String index, String idxPartition, boolean score) {
boolean lateMaterializationEnabled = EsqlCapabilities.Cap.ENABLE_REDUCE_NODE_LATE_MATERIALIZATION.isEnabled();
if (score && lateMaterializationEnabled == false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same here - the cap is always enabled - do we still need this check since this is a test only for single node? (so it's not used for bwc tests).

Copy link
Member Author

@carlosdelest carlosdelest Feb 27, 2026

Choose a reason for hiding this comment

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

👍 done in 15cd5aa

* </ul>
*/
private static PartitioningStrategy highSpeedAutoStrategy(Query query) {
public static PartitioningStrategy highSpeedAutoStrategy(Query query) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick - but do we need this to be public 🙈

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, now we don't - fixed in 21293eb, thanks!

@carlosdelest carlosdelest enabled auto-merge (squash) February 27, 2026 14:56
@carlosdelest carlosdelest changed the title ES|QL - LuceneTopNSourceOperator data partition strategy using task concurrency ES|QL - LuceneTopNSourceOperator data partition strategy uses ContextIndexSearcher slicing Feb 27, 2026
@carlosdelest
Copy link
Member Author

@elasticsearchmachine run elasticsearch-ci/part-3

@carlosdelest
Copy link
Member Author

@elasticsearchmachine run elasticsearch-ci/part-3

@carlosdelest carlosdelest merged commit f589c0c into elastic:main Mar 1, 2026
35 checks passed
tballison pushed a commit to tballison/elasticsearch that referenced this pull request Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>enhancement :Search Relevance/ES|QL Search functionality in ES|QL Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants