Skip to content

Commit 4cda8c2

Browse files
authored
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.
1 parent a644b03 commit 4cda8c2

File tree

5 files changed

+209
-99
lines changed

5 files changed

+209
-99
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: []

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
}

0 commit comments

Comments
 (0)