Skip to content

Commit eee423a

Browse files
kderussoelasticsearchmachinecarlosdelestleemthompo
authored
[ES|QL] Add MATCH_PHRASE (#127661)
* Initial commit of match_phrase * Add MatchPhraseQueryTests * First pass at CSV specs * Update docs/changelog/127661.yaml * Refactor so MatchPhrase doesn't use all fulltext test cases, just text only * Fix tests * Add some CSV test cases * Fix test * Update changelog * Update tests * Comment out MATCH_PHRASE in search-functions Markdown * Minor PR feedback * PR feedback - refactor/consolidate code * Add some more tests * Fix some tests * [CI] Auto commit changes from spotless * Fix tests * PR feedback - add tests, support boost and numeric data * Revert "PR feedback - add tests, support boost and numeric data" This reverts commit 4e7a699. * Apply testing/PR feedback outside numeric support only * Regenerate docs * Add negative test * Update x-pack/plugin/esql/qa/testFixtures/src/main/resources/match-phrase-function.csv-spec Co-authored-by: Carlos Delgado <[email protected]> * Update x-pack/plugin/esql/qa/testFixtures/src/main/resources/match-phrase-function.csv-spec Co-authored-by: Carlos Delgado <[email protected]> * Update x-pack/plugin/esql/qa/testFixtures/src/main/resources/match-phrase-function.csv-spec Co-authored-by: Carlos Delgado <[email protected]> * PR feedback * Fix auto-commit error * Regenerate docs * Update x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/MatchPhrase.java Co-authored-by: Liam Thompson <[email protected]> * Remove non text field types * Fake test data * Remove tests that no longer should pass without ip/date/version support * Put real data in score tests now that I was able to engineer a failure * Realized the scoring test might be flakey because how it was written, updated * PR feedback * PR feedback * [CI] Auto commit changes from spotless * Add check to MatchPhrase tests * Fix merge errors * [CI] Auto commit changes from spotless * Test generated docs * Add additional verifier tests --------- Co-authored-by: elasticsearchmachine <[email protected]> Co-authored-by: Carlos Delgado <[email protected]> Co-authored-by: Liam Thompson <[email protected]>
1 parent aa0a829 commit eee423a

File tree

30 files changed

+1824
-73
lines changed

30 files changed

+1824
-73
lines changed

docs/changelog/127661.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 127661
2+
summary: Add MATCH_PHRASE
3+
area: ES|QL
4+
type: enhancement
5+
issues: []

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

Lines changed: 6 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/examples/match_phrase.md

Lines changed: 22 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/functionNamedParams/match_phrase.md

Lines changed: 16 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/layout/match_phrase.md

Lines changed: 36 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/parameters/match_phrase.md

Lines changed: 13 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: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
* [preview] [`KQL`](../../functions-operators/search-functions.md#esql-kql)
22
* [preview] [`MATCH`](../../functions-operators/search-functions.md#esql-match)
3+
% * [preview] [
4+
`MATCH_PHRASE`](../../functions-operators/search-functions.md#esql-match-phrase)
35
* [preview] [`QSTR`](../../functions-operators/search-functions.md#esql-qstr)
4-
% * [preview] [`TERM`](../../functions-operators/search-functions.md#esql-term)
6+
% * [preview] [
7+
`TERM`](../../functions-operators/search-functions.md#esql-term)

docs/reference/query-languages/esql/functions-operators/search-functions.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,46 @@ mapped_pages:
66

77
# {{esql}} Search functions [esql-search-functions]
88

9-
Use these functions for [full-text search](docs-content://solutions/search/full-text.md) and [semantic search](docs-content://solutions/search/semantic-search/semantic-search-semantic-text.md).
9+
Use these functions
10+
for [full-text search](docs-content://solutions/search/full-text.md)
11+
and [semantic search](docs-content://solutions/search/semantic-search/semantic-search-semantic-text.md).
1012

11-
Get started with {{esql}} for search use cases with our [hands-on tutorial](docs-content://solutions/search/esql-search-tutorial.md).
13+
Get started with {{esql}} for search use cases with
14+
our [hands-on tutorial](docs-content://solutions/search/esql-search-tutorial.md).
1215

13-
Full text functions can be used to match [multivalued fields](/reference/query-languages/esql/esql-multivalued-fields.md). A multivalued field that contains a value that matches a full text query is considered to match the query.
16+
Full text functions can be used to
17+
match [multivalued fields](/reference/query-languages/esql/esql-multivalued-fields.md).
18+
A multivalued field that contains a value that matches a full text query is
19+
considered to match the query.
1420

15-
Full text functions are significantly more performant for text search use cases on large data sets than using pattern matching or regular expressions with `LIKE` or `RLIKE`
21+
Full text functions are significantly more performant for text search use cases
22+
on large data sets than using pattern matching or regular expressions with
23+
`LIKE` or `RLIKE`
1624

17-
See [full text search limitations](/reference/query-languages/esql/limitations.md#esql-limitations-full-text-search) for information on the limitations of full text search.
25+
See [full text search limitations](/reference/query-languages/esql/limitations.md#esql-limitations-full-text-search)
26+
for information on the limitations of full text search.
1827

1928
{{esql}} supports these full-text search functions:
2029

2130
:::{include} ../_snippets/lists/search-functions.md
2231
:::
2332

24-
2533
:::{include} ../_snippets/functions/layout/kql.md
2634
:::
2735

2836
:::{include} ../_snippets/functions/layout/match.md
2937
:::
3038

39+
% MATCH_PHRASE is currently hidden
40+
% :::{include} ../_snippets/functions/layout/match_phrase.md
41+
% :::
42+
3143
:::{include} ../_snippets/functions/layout/qstr.md
3244
:::
3345

3446
% TERM is currently a hidden feature
35-
% To make it visible again, uncomment this and the line in lists/search-functions.md
47+
% To make it visible again, uncomment this and the line in
48+
lists/search-functions.md
3649
% :::{include} ../_snippets/functions/layout/term.md
3750
% :::
3851

docs/reference/query-languages/esql/images/functions/match_phrase.svg

Lines changed: 1 addition & 0 deletions
Loading

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

Lines changed: 64 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/kibana/docs/functions/match_phrase.md

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

server/src/main/java/org/elasticsearch/index/query/MatchPhraseQueryBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ public MatchPhraseQueryBuilder zeroTermsQuery(ZeroTermsQueryOption zeroTermsQuer
129129
return this;
130130
}
131131

132+
public MatchPhraseQueryBuilder zeroTermsQuery(String zeroTermsQueryString) {
133+
ZeroTermsQueryOption zeroTermsQueryOption = ZeroTermsQueryOption.readFromString(zeroTermsQueryString);
134+
return zeroTermsQuery(zeroTermsQueryOption);
135+
}
136+
132137
public ZeroTermsQueryOption zeroTermsQuery() {
133138
return this.zeroTermsQuery;
134139
}

server/src/main/java/org/elasticsearch/index/query/ZeroTermsQueryOption.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ public static ZeroTermsQueryOption readFromStream(StreamInput in) throws IOExcep
5555
throw new ElasticsearchException("unknown serialized type [" + ord + "]");
5656
}
5757

58+
public static ZeroTermsQueryOption readFromString(String input) {
59+
for (ZeroTermsQueryOption zeroTermsQuery : ZeroTermsQueryOption.values()) {
60+
if (zeroTermsQuery.name().equalsIgnoreCase(input)) {
61+
return zeroTermsQuery;
62+
}
63+
}
64+
throw new ElasticsearchException("unknown serialized type [" + input + "]");
65+
}
66+
5867
@Override
5968
public void writeTo(StreamOutput out) throws IOException {
6069
out.writeVInt(this.ordinal);

0 commit comments

Comments
 (0)