Skip to content

Commit bdd93c9

Browse files
authored
ESQL: Fix constant keyword optimization (#129278) (#129354)
* ESQL: Fix constant keyword optimization (#129278) Fixes the ESQL's detection of `constant_keyword` fields. We unplugged it when we changed a function signature because we didn't have an `@Override` annotation. This plugs it back in and adds it to the integration tests we use for pushing queries to lucene. When you do `| WHERE constant_keyword_field == "itsvalue"` then the whole is removed from the query plan because *all* documents are equal. * Old lucene is different
1 parent 1251218 commit bdd93c9

File tree

7 files changed

+218
-107
lines changed

7 files changed

+218
-107
lines changed

docs/changelog/129278.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 129278
2+
summary: Fix constant keyword optimization
3+
area: ES|QL
4+
type: bug
5+
issues: []

docs/reference/esql/functions/kibana/definition/knn.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/kibana/docs/knn.md

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/main/java/org/elasticsearch/common/lucene/search/CaseInsensitiveTermQuery.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ public CaseInsensitiveTermQuery(Term term) {
2828

2929
@Override
3030
public String toString(String field) {
31-
return this.getClass().getSimpleName() + "{" + field + ":" + term.text() + "}";
31+
StringBuilder buffer = new StringBuilder();
32+
buffer.append(getClass().getSimpleName());
33+
buffer.append('{');
34+
if (term.field().equals(field) == false) {
35+
buffer.append(term.field());
36+
buffer.append(':');
37+
}
38+
buffer.append(term.text());
39+
buffer.append('}');
40+
return buffer.toString();
3241
}
3342
}

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/LocalSourceOperator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ public Page getOutput() {
8282
}
8383

8484
@Override
85-
public void close() {
85+
public void close() {}
8686

87+
@Override
88+
public String toString() {
89+
return "LocalSourceOperator";
8790
}
8891
}

x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/PushQueriesIT.java

Lines changed: 187 additions & 95 deletions
Large diffs are not rendered by default.

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/stats/SearchContextStats.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public boolean canUseEqualityOnSyntheticSourceDelegate(FieldAttribute.FieldName
319319
}
320320

321321
@Override
322-
public String constantValue(FieldName name) {
322+
public String constantValue(FieldAttribute.FieldName name) {
323323
String val = null;
324324
for (SearchExecutionContext ctx : contexts) {
325325
MappedFieldType f = ctx.getFieldType(name.string());

0 commit comments

Comments
 (0)