Skip to content

Commit 600257a

Browse files
committed
Explain
1 parent f872334 commit 600257a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/querydsl/query/SingleValueQuery.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ protected final int doHashCode() {
190190
}
191191
}
192192

193+
/**
194+
* Builds a {@code bool} query combining the "next" query and a {@link SingleValueMatchQuery}.
195+
*/
193196
public static class Builder extends AbstractBuilder {
194197
Builder(QueryBuilder next, String field, Source source) {
195198
super(next, field, source);
@@ -251,6 +254,29 @@ protected AbstractBuilder rewrite(QueryBuilder next) {
251254
}
252255
}
253256

257+
/**
258+
* Builds a {@code bool} query combining the "next" query, a {@link SingleValueMatchQuery},
259+
* and a {@link TermQuery} making sure we didn't ignore any values.
260+
* <p>
261+
* This is used in the case when you do {@code text_field == "foo"} and {@code text_field}
262+
* has a {@code keyword} sub-field. See, {@code text} typed fields can't do our equality -
263+
* they only do matching. But {@code keyword} fields *can* do the equality. In this case
264+
* the "next" query is a {@link TermQuery} like {@code text_field.raw:foo}.
265+
* </p>
266+
* <p>
267+
* But there's a big wrinkle! If you index a field longer than {@code ignore_above} into
268+
* {@code text_field.raw} field then it'll drop its value on the floor. So the
269+
* {@link SingleValueMatchQuery} isn't enough to emulate {@code ==}. You have to remove
270+
* any matches that ignored a field. Luckilly we have {@link IgnoredFieldMapper}! We can
271+
* do a {@link TermQuery} like {@code NOT(_ignored:text_field.raw)} to filter those out.
272+
* </p>
273+
* <p>
274+
* You may be asking "how would the first {@code text_field.raw:foo} query work if the
275+
* value we're searching for is very long? In that case we never use this query at all.
276+
* We have to delegate the filtering to the compute engine. No fancy lucene searches in
277+
* that case.
278+
* </p>
279+
*/
254280
public static class SyntheticSourceDelegateBuilder extends AbstractBuilder {
255281
SyntheticSourceDelegateBuilder(QueryBuilder next, String field, Source source) {
256282
super(next, field, source);

0 commit comments

Comments
 (0)