Skip to content

Commit 2b32326

Browse files
Merge remote-tracking branch 'elastic/8.19' into backport/8.19/pr-130849
2 parents ba94342 + f1f88eb commit 2b32326

File tree

20 files changed

+125
-56
lines changed

20 files changed

+125
-56
lines changed

docs/changelog/130914.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 130914
2+
summary: Fix LIMIT NPE with null value
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 130908

docs/reference/esql/esql-limitations.asciidoc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,17 @@ the <<esql-mv-functions,multivalue functions>>.
302302
=== Kibana limitations
303303

304304
include::esql-kibana.asciidoc[tag=limitations]
305+
306+
[discrete]
307+
[[esql-known-issues]]
308+
== Known issues
309+
310+
A bug in the ES|QL STATS command may yield incorrect results. The bug only happens in very specific cases that follow this pattern: `STATS ... BY keyword1, keyword2`, i.e. the command must have exactly two grouping fields, both keywords, where the first field has high cardinality (more than 65k distinct values).
311+
312+
The bug is described in detail in [this issue](https://github.com/elastic/elasticsearch/issues/130644).
313+
The problem was introduced in 8.16.0 and [fixed](https://github.com/elastic/elasticsearch/pull/130705) in 8.17.9, 8.18.7.
314+
315+
Possible workarounds include:
316+
* switching the order of the grouping keys (eg. `STATS ... BY keyword2, keyword1`, if the `keyword2` has a lower cardinality)
317+
* reducing the grouping key cardinality, by filtering out values before STATS
318+

docs/reference/release-notes/8.16.0.asciidoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,13 @@ Snapshot/Restore::
517517
{esql}::
518518

519519
* Some valid queries using an `ENRICH` command can fail when a match field is used that is absent from some indices or shards, either with a 500 status code due to `NullPointerException` or `ClassCastException` or with a 400 status code and `IllegalArgumentException`. This is fixed in {es-pull}126187[#126187].
520+
521+
* A bug in the ES|QL STATS command may yield incorrect results. The bug only happens in very specific cases that follow this pattern: `STATS ... BY keyword1, keyword2`, i.e. the command must have exactly two grouping fields, both keywords, where the first field has high cardinality (more than 65k distinct values).
522+
523+
The bug is described in detail in [this issue](https://github.com/elastic/elasticsearch/issues/130644).
524+
The problem was introduced in 8.16.0 and [fixed](https://github.com/elastic/elasticsearch/pull/130705) in 8.17.9, 8.18.7.
525+
526+
Possible workarounds include:
527+
* switching the order of the grouping keys (eg. `STATS ... BY keyword2, keyword1`, if the `keyword2` has a lower cardinality)
528+
* reducing the grouping key cardinality, by filtering out values before STATS
529+

rest-api-spec/src/main/resources/rest-api-spec/api/search_mvt.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@
7373
"description":"Determines the geometry type for features in the aggs layer.",
7474
"default":"grid"
7575
},
76+
"grid_agg":{
77+
"type":"enum",
78+
"options":[
79+
"geotile",
80+
"geohex"
81+
],
82+
"description":"Aggregation used to create a grid for `field`.",
83+
"default":"geotile"
84+
},
7685
"size":{
7786
"type":"int",
7887
"description":"Maximum number of features to return in the hits layer. Accepts 0-10000.",

x-pack/plugin/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ tasks.named("yamlRestTestV7CompatTransform").configure({ task ->
230230
task.skipTest("esql/191_lookup_join_on_datastreams/data streams not supported in LOOKUP JOIN", "Added support for aliases in JOINs")
231231
task.skipTest("esql/190_lookup_join/non-lookup index", "Error message changed")
232232
task.skipTest("esql/192_lookup_join_on_aliases/alias-pattern-multiple", "Error message changed")
233+
task.skipTest("esql/10_basic/Test wrong LIMIT parameter", "Error message changed")
233234
})
234235

235236

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
@@ -56,7 +56,7 @@ public Factory(
5656
taskConcurrency,
5757
limit,
5858
false,
59-
ScoreMode.COMPLETE_NO_SCORES
59+
shardContext -> ScoreMode.COMPLETE_NO_SCORES
6060
);
6161
}
6262

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public LuceneMaxFactory(
128128
taskConcurrency,
129129
limit,
130130
false,
131-
ScoreMode.COMPLETE_NO_SCORES
131+
shardContext -> ScoreMode.COMPLETE_NO_SCORES
132132
);
133133
this.fieldName = fieldName;
134134
this.numberType = numberType;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public LuceneMinFactory(
128128
taskConcurrency,
129129
limit,
130130
false,
131-
ScoreMode.COMPLETE_NO_SCORES
131+
shardContext -> ScoreMode.COMPLETE_NO_SCORES
132132
);
133133
this.fieldName = fieldName;
134134
this.numberType = numberType;

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,18 @@ protected Factory(
101101
int taskConcurrency,
102102
int limit,
103103
boolean needsScore,
104-
ScoreMode scoreMode
104+
Function<ShardContext, ScoreMode> scoreModeFunction
105105
) {
106106
this.limit = limit;
107107
this.dataPartitioning = dataPartitioning;
108-
this.sliceQueue = LuceneSliceQueue.create(contexts, queryFunction, dataPartitioning, autoStrategy, taskConcurrency, scoreMode);
108+
this.sliceQueue = LuceneSliceQueue.create(
109+
contexts,
110+
queryFunction,
111+
dataPartitioning,
112+
autoStrategy,
113+
taskConcurrency,
114+
scoreModeFunction
115+
);
109116
this.taskConcurrency = Math.min(sliceQueue.totalSlices(), taskConcurrency);
110117
this.needsScore = needsScore;
111118
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,14 @@ public static LuceneSliceQueue create(
107107
DataPartitioning dataPartitioning,
108108
Function<Query, PartitioningStrategy> autoStrategy,
109109
int taskConcurrency,
110-
ScoreMode scoreMode
110+
Function<ShardContext, ScoreMode> scoreModeFunction
111111
) {
112112
List<LuceneSlice> slices = new ArrayList<>();
113113
Map<String, PartitioningStrategy> partitioningStrategies = new HashMap<>(contexts.size());
114+
114115
for (ShardContext ctx : contexts) {
115116
for (QueryAndTags queryAndExtra : queryFunction.apply(ctx)) {
117+
var scoreMode = scoreModeFunction.apply(ctx);
116118
Query query = queryAndExtra.query;
117119
query = scoreMode.needsScores() ? query : new ConstantScoreQuery(query);
118120
/*

0 commit comments

Comments
 (0)