Skip to content

Commit 29cce29

Browse files
Handle MultiMatch function
1 parent 923dc02 commit 29cce29

File tree

2 files changed

+50
-3
lines changed
  • x-pack/plugin
    • esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext
    • src/yamlRestTest/resources/rest-api-spec/test/esql

2 files changed

+50
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.THIRD;
6565
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isMapExpression;
6666
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isNotNull;
67-
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isNotNullAndFoldable;
6867
import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.isType;
6968
import static org.elasticsearch.xpack.esql.core.type.DataType.BOOLEAN;
7069
import static org.elasticsearch.xpack.esql.core.type.DataType.DATETIME;
@@ -78,6 +77,7 @@
7877
import static org.elasticsearch.xpack.esql.core.type.DataType.TEXT;
7978
import static org.elasticsearch.xpack.esql.core.type.DataType.UNSIGNED_LONG;
8079
import static org.elasticsearch.xpack.esql.core.type.DataType.VERSION;
80+
import static org.elasticsearch.xpack.esql.expression.function.FunctionUtils.resolveTypeQuery;
8181

8282
/**
8383
* Full text function that performs a {@link org.elasticsearch.xpack.esql.querydsl.query.MultiMatchQuery} .
@@ -415,13 +415,21 @@ private TypeResolution resolveOptions() {
415415
}
416416

417417
private TypeResolution resolveQuery() {
418-
return isType(
418+
TypeResolution result = isType(
419419
query(),
420420
QUERY_DATA_TYPES::contains,
421421
sourceText(),
422422
FIRST,
423423
"keyword, boolean, date, date_nanos, double, integer, ip, long, unsigned_long, version"
424-
).and(isNotNullAndFoldable(query(), sourceText(), FIRST));
424+
).and(isNotNull(query(), sourceText(), FIRST));
425+
if (result.unresolved()) {
426+
return result;
427+
}
428+
result = resolveTypeQuery(query(), sourceText());
429+
if (result.equals(TypeResolution.TYPE_RESOLVED) == false) {
430+
return result;
431+
}
432+
return TypeResolution.TYPE_RESOLVED;
425433
}
426434

427435
@Override

x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/230_folding.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,42 @@ Foldable query using PHRASE_MATCH on name but with non-foldable expression:
202202
| LIMIT 5
203203
- match: { error.type: "verification_exception" }
204204
- contains: { error.reason: "Query must be a valid string in [MATCH_PHRASE(name, CONCAT(\"Bob \", name))], found [CONCAT(\"Bob \", name)]" }
205+
206+
---
207+
208+
Foldable query using MULTI_MATCH on name:
209+
- do:
210+
esql.query:
211+
body:
212+
query: |
213+
FROM employees
214+
| WHERE MULTI_MATCH(CONCAT("Bob ", "Johnson"), name)
215+
| KEEP hire_date, salary, salary_change, salary_change_long, name
216+
| LIMIT 5
217+
- match: { columns.0.name: "hire_date" }
218+
- match: { columns.1.name: "salary" }
219+
- match: { columns.2.name: "salary_change" }
220+
- match: { columns.3.name: "salary_change_long" }
221+
- match: { columns.4.name: "name" }
222+
- length: { values: 1 }
223+
- match: { values.0.0: "2021-01-01T00:00:00.000Z" }
224+
- match: { values.0.1: 60000 }
225+
- match: { values.0.2: 200.5 }
226+
- match: { values.0.3: 200 }
227+
- match: { values.0.4: "Bob Johnson" }
228+
229+
---
230+
231+
Foldable query using MULTI_MATCH on name but with non-foldable expression:
232+
- do:
233+
catch: bad_request
234+
esql.query:
235+
body:
236+
query: |
237+
FROM employees
238+
| WHERE MULTI_MATCH(CONCAT("Bob ", name), name)
239+
| KEEP hire_date, salary, salary_change, salary_change_long, name
240+
| LIMIT 5
241+
- match: { error.type: "verification_exception" }
242+
- contains: { error.reason: "Query must be a valid string in [MULTI_MATCH(CONCAT(\"Bob \", name), name)], found [CONCAT(\"Bob \", name)]" }
243+

0 commit comments

Comments
 (0)