Skip to content

Commit b3d8d7c

Browse files
Merge branch 'main' into kibana-esql-docs-updates
2 parents 55f406e + 4f019d1 commit b3d8d7c

File tree

24 files changed

+375
-104
lines changed

24 files changed

+375
-104
lines changed

docs/changelog/125930.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 125930
2+
summary: Infer the score mode to use from the Lucene collector
3+
area: "ES|QL"
4+
type: enhancement
5+
issues: []

muted-tests.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,18 +344,12 @@ tests:
344344
- class: org.elasticsearch.xpack.ilm.actions.SearchableSnapshotActionIT
345345
method: testSearchableSnapshotsInHotPhasePinnedToHotNodes
346346
issue: https://github.com/elastic/elasticsearch/issues/125683
347-
- class: org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT
348-
method: test {p0=cat.allocation/10_basic/Node forecasts}
349-
issue: https://github.com/elastic/elasticsearch/issues/125711
350347
- class: org.elasticsearch.xpack.migrate.action.ReindexDataStreamTransportActionIT
351348
method: testAlreadyUpToDateDataStream
352349
issue: https://github.com/elastic/elasticsearch/issues/125727
353350
- class: org.elasticsearch.index.engine.ThreadPoolMergeSchedulerStressTestIT
354351
method: testMergingFallsBehindAndThenCatchesUp
355352
issue: https://github.com/elastic/elasticsearch/issues/125744
356-
- class: org.elasticsearch.test.rest.ClientYamlTestSuiteIT
357-
method: test {yaml=cat.allocation/10_basic/Node forecasts}
358-
issue: https://github.com/elastic/elasticsearch/issues/125661
359353
- class: org.elasticsearch.xpack.esql.spatial.SpatialExtentAggregationNoLicenseIT
360354
method: testStExtentAggregationWithPoints
361355
issue: https://github.com/elastic/elasticsearch/issues/125735
@@ -380,9 +374,6 @@ tests:
380374
- class: org.elasticsearch.multiproject.test.CoreWithMultipleProjectsClientYamlTestSuiteIT
381375
method: test {yaml=search.vectors/41_knn_search_bbq_hnsw/Test index configured rescore vector score consistency}
382376
issue: https://github.com/elastic/elasticsearch/issues/125902
383-
- class: org.elasticsearch.smoketest.SmokeTestMultiNodeClientYamlTestSuiteIT
384-
method: test {yaml=cat.allocation/10_basic/Node forecasts}
385-
issue: https://github.com/elastic/elasticsearch/issues/125848
386377
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
387378
method: test {p0=ml/start_data_frame_analytics/Test start given dest index is not empty}
388379
issue: https://github.com/elastic/elasticsearch/issues/125909

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/cat.allocation/10_basic.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295
( [-\w.]+ \s+
296296
[-\w.]+ \s+
297297
[-\w.]+ \s+
298-
[\w]+
298+
[-\w.]+
299299
\n
300300
)+
301301
$/

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexPrivilege.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,13 @@ public static Set<String> names() {
482482
* @see Privilege#sortByAccessLevel
483483
*/
484484
public static Collection<String> findPrivilegesThatGrant(String action) {
485+
return findPrivilegesThatGrant(action, p -> p.getSelectorPredicate().test(IndexComponentSelector.DATA));
486+
}
487+
488+
public static Collection<String> findPrivilegesThatGrant(String action, Predicate<IndexPrivilege> preCondition) {
485489
return VALUES.entrySet()
486490
.stream()
487-
// Only include privileges that grant data access; failures access is handled separately in authorization failure messages
488-
.filter(e -> e.getValue().selectorPredicate.test(IndexComponentSelector.DATA))
491+
.filter(e -> preCondition.test(e.getValue()))
489492
.filter(e -> e.getValue().predicate.test(action))
490493
.map(Map.Entry::getKey)
491494
.toList();

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexPrivilegeTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Collection;
2424
import java.util.List;
2525
import java.util.Set;
26+
import java.util.function.Predicate;
2627

2728
import static org.elasticsearch.xpack.core.security.authz.privilege.IndexPrivilege.findPrivilegesThatGrant;
2829
import static org.hamcrest.Matchers.containsInAnyOrder;
@@ -68,6 +69,16 @@ public void testFindPrivilegesThatGrant() {
6869
equalTo(List.of("monitor", "cross_cluster_replication", "manage", "all"))
6970
);
7071
assertThat(findPrivilegesThatGrant(RefreshAction.NAME), equalTo(List.of("maintenance", "manage", "all")));
72+
73+
if (DataStream.isFailureStoreFeatureFlagEnabled()) {
74+
Predicate<IndexPrivilege> failuresOnly = p -> p.getSelectorPredicate() == IndexComponentSelectorPredicate.FAILURES;
75+
assertThat(findPrivilegesThatGrant(TransportSearchAction.TYPE.name(), failuresOnly), equalTo(List.of("read_failure_store")));
76+
assertThat(findPrivilegesThatGrant(TransportIndexAction.NAME, failuresOnly), equalTo(List.of()));
77+
assertThat(findPrivilegesThatGrant(TransportUpdateAction.NAME, failuresOnly), equalTo(List.of()));
78+
assertThat(findPrivilegesThatGrant(TransportDeleteAction.NAME, failuresOnly), equalTo(List.of()));
79+
assertThat(findPrivilegesThatGrant(IndicesStatsAction.NAME, failuresOnly), equalTo(List.of("manage_failure_store")));
80+
assertThat(findPrivilegesThatGrant(RefreshAction.NAME, failuresOnly), equalTo(List.of("manage_failure_store")));
81+
}
7182
}
7283

7384
public void testGet() {

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneCountOperator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public Factory(
4949
int taskConcurrency,
5050
int limit
5151
) {
52-
super(contexts, queryFunction, dataPartitioning, taskConcurrency, limit, ScoreMode.COMPLETE_NO_SCORES);
52+
super(contexts, weightFunction(queryFunction, ScoreMode.COMPLETE_NO_SCORES), dataPartitioning, taskConcurrency, limit, false);
5353
}
5454

5555
@Override

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMaxFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.List;
2424
import java.util.function.Function;
2525

26+
import static org.elasticsearch.compute.lucene.LuceneOperator.weightFunction;
27+
2628
/**
2729
* Factory that generates an operator that finds the max value of a field using the {@link LuceneMinMaxOperator}.
2830
*/
@@ -121,7 +123,7 @@ public LuceneMaxFactory(
121123
NumberType numberType,
122124
int limit
123125
) {
124-
super(contexts, queryFunction, dataPartitioning, taskConcurrency, limit, ScoreMode.COMPLETE_NO_SCORES);
126+
super(contexts, weightFunction(queryFunction, ScoreMode.COMPLETE_NO_SCORES), dataPartitioning, taskConcurrency, limit, false);
125127
this.fieldName = fieldName;
126128
this.numberType = numberType;
127129
}

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneMinFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.List;
2424
import java.util.function.Function;
2525

26+
import static org.elasticsearch.compute.lucene.LuceneOperator.weightFunction;
27+
2628
/**
2729
* Factory that generates an operator that finds the min value of a field using the {@link LuceneMinMaxOperator}.
2830
*/
@@ -121,7 +123,7 @@ public LuceneMinFactory(
121123
NumberType numberType,
122124
int limit
123125
) {
124-
super(contexts, queryFunction, dataPartitioning, taskConcurrency, limit, ScoreMode.COMPLETE_NO_SCORES);
126+
super(contexts, weightFunction(queryFunction, ScoreMode.COMPLETE_NO_SCORES), dataPartitioning, taskConcurrency, limit, false);
125127
this.fieldName = fieldName;
126128
this.numberType = numberType;
127129
}

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneOperator.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.apache.lucene.search.BulkScorer;
1212
import org.apache.lucene.search.ConstantScoreQuery;
1313
import org.apache.lucene.search.DocIdSetIterator;
14-
import org.apache.lucene.search.IndexSearcher;
1514
import org.apache.lucene.search.LeafCollector;
1615
import org.apache.lucene.search.Query;
1716
import org.apache.lucene.search.ScoreMode;
@@ -84,28 +83,27 @@ public abstract static class Factory implements SourceOperator.SourceOperatorFac
8483
protected final DataPartitioning dataPartitioning;
8584
protected final int taskConcurrency;
8685
protected final int limit;
87-
protected final ScoreMode scoreMode;
86+
protected final boolean needsScore;
8887
protected final LuceneSliceQueue sliceQueue;
8988

9089
/**
9190
* Build the factory.
9291
*
93-
* @param scoreMode the {@link ScoreMode} passed to {@link IndexSearcher#createWeight}
92+
* @param needsScore Whether the score is needed.
9493
*/
9594
protected Factory(
9695
List<? extends ShardContext> contexts,
97-
Function<ShardContext, Query> queryFunction,
96+
Function<ShardContext, Weight> weightFunction,
9897
DataPartitioning dataPartitioning,
9998
int taskConcurrency,
10099
int limit,
101-
ScoreMode scoreMode
100+
boolean needsScore
102101
) {
103102
this.limit = limit;
104-
this.scoreMode = scoreMode;
105103
this.dataPartitioning = dataPartitioning;
106-
var weightFunction = weightFunction(queryFunction, scoreMode);
107104
this.sliceQueue = LuceneSliceQueue.create(contexts, weightFunction, dataPartitioning, taskConcurrency);
108105
this.taskConcurrency = Math.min(sliceQueue.totalSlices(), taskConcurrency);
106+
this.needsScore = needsScore;
109107
}
110108

111109
public final int taskConcurrency() {

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/LuceneSourceOperator.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.apache.lucene.search.LeafCollector;
1212
import org.apache.lucene.search.Query;
1313
import org.apache.lucene.search.Scorable;
14-
import org.apache.lucene.search.ScoreMode;
1514
import org.elasticsearch.compute.data.BlockFactory;
1615
import org.elasticsearch.compute.data.DocBlock;
1716
import org.elasticsearch.compute.data.DocVector;
@@ -56,17 +55,24 @@ public Factory(
5655
int taskConcurrency,
5756
int maxPageSize,
5857
int limit,
59-
boolean scoring
58+
boolean needsScore
6059
) {
61-
super(contexts, queryFunction, dataPartitioning, taskConcurrency, limit, scoring ? COMPLETE : COMPLETE_NO_SCORES);
60+
super(
61+
contexts,
62+
weightFunction(queryFunction, needsScore ? COMPLETE : COMPLETE_NO_SCORES),
63+
dataPartitioning,
64+
taskConcurrency,
65+
limit,
66+
needsScore
67+
);
6268
this.maxPageSize = maxPageSize;
6369
// TODO: use a single limiter for multiple stage execution
6470
this.limiter = limit == NO_LIMIT ? Limiter.NO_LIMIT : new Limiter(limit);
6571
}
6672

6773
@Override
6874
public SourceOperator get(DriverContext driverContext) {
69-
return new LuceneSourceOperator(driverContext.blockFactory(), maxPageSize, sliceQueue, limit, limiter, scoreMode);
75+
return new LuceneSourceOperator(driverContext.blockFactory(), maxPageSize, sliceQueue, limit, limiter, needsScore);
7076
}
7177

7278
public int maxPageSize() {
@@ -81,8 +87,8 @@ public String describe() {
8187
+ maxPageSize
8288
+ ", limit = "
8389
+ limit
84-
+ ", scoreMode = "
85-
+ scoreMode
90+
+ ", needsScore = "
91+
+ needsScore
8692
+ "]";
8793
}
8894
}
@@ -94,7 +100,7 @@ public LuceneSourceOperator(
94100
LuceneSliceQueue sliceQueue,
95101
int limit,
96102
Limiter limiter,
97-
ScoreMode scoreMode
103+
boolean needsScore
98104
) {
99105
super(blockFactory, maxPageSize, sliceQueue);
100106
this.minPageSize = Math.max(1, maxPageSize / 2);
@@ -104,7 +110,7 @@ public LuceneSourceOperator(
104110
boolean success = false;
105111
try {
106112
this.docsBuilder = blockFactory.newIntVectorBuilder(estimatedSize);
107-
if (scoreMode.needsScores()) {
113+
if (needsScore) {
108114
scoreBuilder = blockFactory.newDoubleVectorBuilder(estimatedSize);
109115
this.leafCollector = new ScoringCollector();
110116
} else {

0 commit comments

Comments
 (0)