Skip to content

Commit 68e9b89

Browse files
more work on translation
1 parent 68d732a commit 68e9b89

File tree

1 file changed

+12
-6
lines changed
  • x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext

1 file changed

+12
-6
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Match.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ public class Match extends FullTextFunction implements OptionalArgument, PostAna
138138
entry(ZERO_TERMS_QUERY_FIELD.getPreferredName(), KEYWORD)
139139
);
140140

141+
private static final Set<String> MULTIMATCH_SPECIFIC_OPTIONS = Set.of(
142+
SLOP_FIELD.getPreferredName(),
143+
TIE_BREAKER_FIELD.getPreferredName(),
144+
TYPE_FIELD.getPreferredName()
145+
);
146+
141147
// TODO: update descriptions and comments.
142148
@FunctionInfo(
143149
returnType = "boolean",
@@ -511,13 +517,13 @@ protected Query translate(TranslatorHandler handler) {
511517
fieldsWithBoost.put(fieldName, 1.0f);
512518
}
513519

514-
// TODO: check if we have multi_match specific options, like "type".
515-
if (fieldsWithBoost.size() == 1) {
516-
// Translate to Match when having exactly one field.
517-
return new MatchQuery(source(), fieldsWithBoost.keySet().stream().findFirst().get(), queryAsObject(), matchQueryOptions());
520+
var options = matchQueryOptions();
521+
if (fieldsWithBoost.size() != 1 || options.keySet().stream().anyMatch(MULTIMATCH_SPECIFIC_OPTIONS::contains)) {
522+
// For 0 or 2+ fields, or with multimatch-specific options, translate to multi_match.
523+
return new MultiMatchQuery(source(), Objects.toString(queryAsObject()), fieldsWithBoost, options);
518524
} else {
519-
// For 0 or 2+ fields, translate to multi_match.
520-
return new MultiMatchQuery(source(), Objects.toString(queryAsObject()), fieldsWithBoost, matchQueryOptions());
525+
// Translate to Match when having exactly one field.
526+
return new MatchQuery(source(), fieldsWithBoost.keySet().stream().findFirst().get(), queryAsObject(), options);
521527
}
522528
}
523529

0 commit comments

Comments
 (0)