Skip to content

Commit 68d732a

Browse files
fix translation
1 parent 90530e7 commit 68d732a

File tree

1 file changed

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

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
4040
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
4141
import org.elasticsearch.xpack.esql.planner.TranslatorHandler;
42+
import org.elasticsearch.xpack.esql.querydsl.query.MatchQuery;
4243
import org.elasticsearch.xpack.esql.querydsl.query.MultiMatchQuery;
4344
import org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter;
4445

@@ -509,7 +510,15 @@ protected Query translate(TranslatorHandler handler) {
509510
String fieldName = getNameFromFieldAttribute(fieldAttribute);
510511
fieldsWithBoost.put(fieldName, 1.0f);
511512
}
512-
return new MultiMatchQuery(source(), Objects.toString(queryAsObject()), fieldsWithBoost, matchQueryOptions());
513+
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());
518+
} else {
519+
// For 0 or 2+ fields, translate to multi_match.
520+
return new MultiMatchQuery(source(), Objects.toString(queryAsObject()), fieldsWithBoost, matchQueryOptions());
521+
}
513522
}
514523

515524
private static String getNameFromFieldAttribute(FieldAttribute fieldAttribute) {

0 commit comments

Comments
 (0)