Skip to content

Commit 0ebbf82

Browse files
committed
Initial commit of match_phrase
1 parent 6263f44 commit 0ebbf82

File tree

7 files changed

+520
-0
lines changed

7 files changed

+520
-0
lines changed

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);

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,11 @@ public enum Cap {
649649
*/
650650
MATCH_FUNCTION,
651651

652+
/**
653+
* MATCH PHRASE function
654+
*/
655+
MATCH_PHRASE_FUNCTION(Build.current().isSnapshot()),
656+
652657
/**
653658
* KQL function
654659
*/

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.elasticsearch.xpack.esql.expression.function.aggregate.WeightedAvg;
4040
import org.elasticsearch.xpack.esql.expression.function.fulltext.Kql;
4141
import org.elasticsearch.xpack.esql.expression.function.fulltext.Match;
42+
import org.elasticsearch.xpack.esql.expression.function.fulltext.MatchPhrase;
4243
import org.elasticsearch.xpack.esql.expression.function.fulltext.MultiMatch;
4344
import org.elasticsearch.xpack.esql.expression.function.fulltext.QueryString;
4445
import org.elasticsearch.xpack.esql.expression.function.fulltext.Term;
@@ -431,6 +432,7 @@ private static FunctionDefinition[][] functions() {
431432
new FunctionDefinition[] {
432433
def(Kql.class, uni(Kql::new), "kql"),
433434
def(Match.class, tri(Match::new), "match"),
435+
def(MatchPhrase.class, tri(MatchPhrase::new), "match_phrase"),
434436
def(MultiMatch.class, MultiMatch::new, "multi_match"),
435437
def(QueryString.class, bi(QueryString::new), "qstr") } };
436438

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ private static void checkFullTextQueryFunctions(LogicalPlan plan, Failures failu
209209
m -> "[" + m.functionName() + "] " + m.functionType(),
210210
failures
211211
);
212+
checkCommandsBeforeExpression(
213+
plan,
214+
condition,
215+
MatchPhrase.class,
216+
lp -> (lp instanceof Limit == false) && (lp instanceof Aggregate == false),
217+
m -> "[" + m.functionName() + "] " + m.functionType(),
218+
failures
219+
);
212220
checkCommandsBeforeExpression(
213221
plan,
214222
condition,

0 commit comments

Comments
 (0)