Skip to content

Commit 5ec2c80

Browse files
committed
[ES|QL] Add MATCH_PHRASE (elastic#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]> (cherry picked from commit eee423a) # Conflicts: # docs/reference/esql/functions/description/match_phrase.md # docs/reference/esql/functions/examples/match_phrase.md # docs/reference/esql/functions/kibana/definition/match_phrase.json # docs/reference/esql/functions/kibana/docs/match_phrase.md # docs/reference/query-languages/esql/_snippets/lists/search-functions.md # docs/reference/query-languages/esql/functions-operators/search-functions.md # x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java # x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java # x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/FullTextFunction.java # x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/Match.java # x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/QueryString.java # x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java
1 parent 2474a1f commit 5ec2c80

File tree

24 files changed

+1731
-80
lines changed

24 files changed

+1731
-80
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: []
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
% This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it.
2+
3+
**Supported function named parameters**
4+
5+
`zero_terms_query`
6+
: (keyword) Indicates whether all documents or none are returned if the analyzer removes all tokens, such as when using a stop filter. Defaults to none.
7+
8+
`boost`
9+
: (float) Floating point number used to decrease or increase the relevance scores of the query. Defaults to 1.0.
10+
11+
`analyzer`
12+
: (keyword) Analyzer used to convert the text in the query value into token. Defaults to the index-time analyzer mapped for the field. If no analyzer is mapped, the index’s default analyzer is used.
13+
14+
`slop`
15+
: (integer) Maximum number of positions allowed between matching tokens. Defaults to 0. Transposed terms have a slop of 2.
16+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
% This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it.
2+
3+
## `MATCH_PHRASE` [esql-match_phrase]
4+
:::{warning}
5+
Do not use on production environments. This functionality is in technical preview and
6+
may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview
7+
are not subject to the support SLA of official GA features.
8+
:::
9+
10+
:::{note}
11+
###### Serverless: GA, Elastic Stack: COMING
12+
Support for optional named parameters is only available in serverless, or in a future {{es}} release
13+
:::
14+
15+
**Syntax**
16+
17+
:::{image} ../../../images/functions/match_phrase.svg
18+
:alt: Embedded
19+
:class: text-center
20+
:::
21+
22+
23+
:::{include} ../parameters/match_phrase.md
24+
:::
25+
26+
:::{include} ../description/match_phrase.md
27+
:::
28+
29+
:::{include} ../types/match_phrase.md
30+
:::
31+
32+
:::{include} ../functionNamedParams/match_phrase.md
33+
:::
34+
35+
:::{include} ../examples/match_phrase.md
36+
:::
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
% This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it.
2+
3+
**Parameters**
4+
5+
`field`
6+
: Field that the query will target.
7+
8+
`query`
9+
: Value to find in the provided field.
10+
11+
`options`
12+
: (Optional) MatchPhrase additional options as [function named parameters](/reference/query-languages/esql/esql-syntax.md#esql-function-named-params). See [match_phrase query](/reference/query-languages/query-dsl/query-dsl-match-query.md#query-dsl-match-query-phrase) for more information.
13+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
% This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it.
2+
3+
**Supported types**
4+
5+
| field | query | options | result |
6+
| --- | --- | --- | --- |
7+
| keyword | keyword | named parameters | boolean |
8+
| text | keyword | named parameters | boolean |
9+
Lines changed: 1 addition & 0 deletions
Loading

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)