Skip to content

Commit 4e7a699

Browse files
committed
PR feedback - add tests, support boost and numeric data
1 parent f71620c commit 4e7a699

File tree

10 files changed

+879
-39
lines changed

10 files changed

+879
-39
lines changed

docs/reference/query-languages/esql/_snippets/functions/functionNamedParams/match_phrase.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/_snippets/functions/types/match_phrase.md

Lines changed: 18 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/kibana/definition/functions/match_phrase.json

Lines changed: 413 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/qa/testFixtures/src/main/resources/match-phrase-function.csv-spec

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,70 @@ emp_no:integer | first_name:keyword | last_name:keyword
269269
10043 | Yishay | Tzvieli
270270
;
271271

272+
testMatchPhraseBooleanField
273+
required_capability: match_phrase_function
274+
required_capability: match_additional_types
275+
276+
from employees
277+
| where match_phrase(still_hired, true) and height > 2.08
278+
| keep first_name, still_hired, height;
279+
ignoreOrder:true
280+
281+
first_name:keyword | still_hired:boolean | height:double
282+
Saniya | true | 2.1
283+
Yongqiao | true | 2.1
284+
Kwee | true | 2.1
285+
Amabile | true | 2.09
286+
;
287+
288+
testMatchPhraseIntegerField
289+
required_capability: match_phrase_function
290+
required_capability: match_additional_types
291+
292+
from employees
293+
| where match(emp_no, 10004)
294+
| keep emp_no, first_name;
295+
296+
emp_no:integer | first_name:keyword
297+
10004 | Chirstian
298+
;
299+
300+
testMatchPhraseDoubleField
301+
required_capability: match_phrase_function
302+
required_capability: match_additional_types
303+
304+
from employees
305+
| where match_phrase(salary_change, 9.07)
306+
| keep emp_no, salary_change;
307+
308+
emp_no:integer | salary_change:double
309+
10014 | [-1.89, 9.07]
310+
;
311+
312+
testMatchPhraseLongField
313+
required_capability: match_phrase_function
314+
required_capability: match_additional_types
315+
316+
from date_nanos
317+
| where match_phrase(num, 1698069301543123456)
318+
| keep num;
319+
320+
num:long
321+
1698069301543123456
322+
;
323+
324+
testMatchPhraseUnsignedLongField
325+
required_capability: match_phrase_function
326+
required_capability: match_additional_types
327+
328+
from ul_logs
329+
| where match_phrase(bytes_out, 12749081495402663265)
330+
| keep bytes_out;
331+
332+
bytes_out:unsigned_long
333+
12749081495402663265
334+
;
335+
272336
testMatchPhraseVersionField
273337
required_capability: match_phrase_function
274338

@@ -327,6 +391,21 @@ book_no:keyword
327391
7140
328392
;
329393

394+
testMatchPhraseWithOptionsBoost
395+
required_capability: match_phrase_function
396+
from books
397+
| where match_phrase(title, "Lord of the Rings", {"boost": 5})
398+
| keep book_no;
399+
ignoreOrder:true
400+
401+
book_no:keyword
402+
2714
403+
2675
404+
4023
405+
7140
406+
;
407+
408+
330409
testMatchPhraseWithOptionsZeroTermsNone
331410
required_capability: match_phrase_function
332411
from books
@@ -382,3 +461,94 @@ book_no:keyword
382461
4023
383462
7140
384463
;
464+
465+
testMatchPhraseInStatsNonPushable
466+
required_capability: match_phrase_function
467+
required_capability: full_text_functions_in_stats_where
468+
469+
from books
470+
| where length(title) > 40
471+
| stats c = count(*) where match_phrase(title, "Lord of the Rings")
472+
;
473+
474+
c:long
475+
3
476+
;
477+
478+
testMatchPhraseInStatsPushableAndNonPushable
479+
required_capability: match_phrase_function
480+
required_capability: full_text_functions_in_stats_where
481+
482+
from books
483+
| stats c = count(*) where (match_phrase(title, "lord of the rings") and ratings > 4.5) or (match(author, "fyodor dostoevsky") and length(title) > 50)
484+
;
485+
486+
c:long
487+
6
488+
;
489+
490+
testMatchPhraseInStatsPushable
491+
required_capability: match_phrase_function
492+
required_capability: full_text_functions_in_stats_where
493+
494+
from books
495+
| stats c = count(*) where match_phrase(author, "j. r. r. tolkien")
496+
;
497+
498+
c:long
499+
9
500+
;
501+
502+
testMatchPhraseInStatsWithOptions
503+
required_capability: match_phrase_function
504+
required_capability: full_text_functions_in_stats_where
505+
506+
FROM books
507+
| STATS c = count(*) where match_phrase(title, "There and Back Again", {"slop": "5"})
508+
;
509+
510+
c:long
511+
1
512+
;
513+
514+
testMatchPhraseInStatsWithNonPushableDisjunctions
515+
required_capability: match_phrase_function
516+
required_capability: full_text_functions_in_stats_where
517+
518+
FROM books
519+
| STATS c = count(*) where match_phrase(title, "lord of the rings") or length(title) > 130
520+
;
521+
522+
c:long
523+
5
524+
;
525+
526+
testMatchPhraseInStatsWithMultipleAggs
527+
required_capability: match_phrase_function
528+
required_capability: full_text_functions_in_stats_where
529+
FROM books
530+
| STATS c = count(*) where match_phrase(title, "lord of the rings"), m = max(book_no::integer) where match_phrase(author, "j. r. r. tolkien"), n = min(book_no::integer) where match_phrase(author, "fyodor dostoevsky")
531+
;
532+
533+
c:long | m:integer | n:integer
534+
4 | 7670 | 1211
535+
;
536+
537+
538+
testMatchPhraseInStatsWithGrouping
539+
required_capability: match_phrase_function
540+
required_capability: full_text_functions_in_stats_where
541+
FROM books
542+
| STATS r = AVG(ratings) where match_phrase(title, "Lord of the Rings") by author | WHERE r is not null
543+
;
544+
ignoreOrder: true
545+
546+
r:double | author: text
547+
4.75 | Alan Lee
548+
4.674999952316284 | J. R. R. Tolkien
549+
4.670000076293945 | John Ronald Reuel Tolkien
550+
4.670000076293945 | Agnes Perkins
551+
4.670000076293945 | Charles Adolph Huttar
552+
4.670000076293945 | Walter Scheps
553+
4.559999942779541 | J.R.R. Tolkien
554+
;

x-pack/plugin/esql/qa/testFixtures/src/main/resources/scoring.csv-spec

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,3 +558,29 @@ from books metadata _score
558558
avg_score:double | max_score:double | min_score:double
559559
3.869828939437866 | 5.123856544494629 | 3.0124807357788086
560560
;
561+
562+
testMatchPhraseWithScore
563+
required_capability: match_phrase
564+
required_capability: metadata_score
565+
566+
from books metadata _score
567+
| where match_phrase(title, "J. R. R. Tolkien")
568+
| keep book_no, title, author, _score;
569+
ignoreOrder:true
570+
571+
book_no:keyword | title:text | author:text | _score:double
572+
2847 | To Love A Dark Stranger (Lovegram Historical Romance) | Colleen Faulkner | 1.9662091732025146
573+
;
574+
575+
testMatchPhraseWithScoreBoost
576+
required_capability: match_phrase
577+
required_capability: metadata_score
578+
579+
from books metadata _score
580+
| where match_phrase(title, "J. R. R. Tolkien", {"boost": 5})
581+
| keep book_no, title, author, _score;
582+
ignoreOrder:true
583+
584+
book_no:keyword | title:text | author:text | _score:double
585+
2847 | To Love A Dark Stranger (Lovegram Historical Romance) | Colleen Faulkner | 1.9662091732025146
586+
;

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/MatchPhraseFunctionIT.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.hamcrest.Matchers;
1717
import org.junit.Before;
1818

19+
import java.util.Collections;
1920
import java.util.List;
2021

2122
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
@@ -45,6 +46,36 @@ public void testSimpleWhereMatchPhrase() {
4546
}
4647
}
4748

49+
public void testSimpleWhereMatchPhraseNoResults() {
50+
var query = """
51+
FROM test
52+
| WHERE match_phrase(content, "fox brown")
53+
| KEEP id
54+
| SORT id
55+
""";
56+
57+
try (var resp = run(query)) {
58+
assertColumnNames(resp.columns(), List.of("id"));
59+
assertColumnTypes(resp.columns(), List.of("integer"));
60+
assertValues(resp.values(), Collections.emptyList());
61+
}
62+
}
63+
64+
public void testSimpleWhereMatchPhraseAndSlop() {
65+
var query = """
66+
FROM test
67+
| WHERE match_phrase(content, "fox brown", {"slop": 5})
68+
| KEEP id
69+
| SORT id
70+
""";
71+
72+
try (var resp = run(query)) {
73+
assertColumnNames(resp.columns(), List.of("id"));
74+
assertColumnTypes(resp.columns(), List.of("integer"));
75+
assertValues(resp.values(), List.of(List.of(1), List.of(6)));
76+
}
77+
}
78+
4879
public void testCombinedWhereMatchPhrase() {
4980
var query = """
5081
FROM test

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/ScoringIT.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public static List<Object[]> params() {
5353
if (EsqlCapabilities.Cap.TERM_FUNCTION.isEnabled()) {
5454
params.add(new Object[] { "term(content, \"fox\")" });
5555
}
56+
if (EsqlCapabilities.Cap.MATCH_PHRASE_FUNCTION.isEnabled()) {
57+
params.add(new Object[] { "match_phrase(content, \"fox\")" });
58+
}
5659
return params;
5760
}
5861

0 commit comments

Comments
 (0)