Skip to content

Commit ba933d9

Browse files
committed
Add specific docs for match operator using a separate class for holding documentation
1 parent 9c0709f commit ba933d9

File tree

9 files changed

+100
-22
lines changed

9 files changed

+100
-22
lines changed

docs/reference/esql/functions/kibana/definition/match.json

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

docs/reference/esql/functions/kibana/definition/match_operator.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/kibana/docs/match_operator.md

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

docs/reference/esql/functions/search.asciidoc

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@ The match operator is equivalent to the <<esql-match,match function>>.
1414
[.text-center]
1515
image::esql/functions/signature/match_operator.svg[Embedded,opts=inline]
1616

17-
include::types/match.asciidoc[]
18-
19-
[source.merge.styled,esql]
20-
----
21-
include::{esql-specs}/match-operator.csv-spec[tag=match-with-field]
22-
----
23-
[%header.monospaced.styled,format=dsv,separator=|]
24-
|===
25-
include::{esql-specs}/match-operator.csv-spec[tag=match-with-field-result]
26-
|===
17+
include::../parameters/match_operator.asciidoc[]
18+
include::../description/match_operator.asciidoc[]
19+
include::../types/match_operator.asciidoc[]
20+
include::../examples/match.asciidoc[]

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static List<NamedWriteableRegistry.Entry> getNamedWriteables() {
2525
entries.add(MultiMatchQueryPredicate.ENTRY);
2626
entries.add(QueryString.ENTRY);
2727
entries.add(Match.ENTRY);
28+
entries.add(MatchOperator.ENTRY);
2829
entries.add(Kql.ENTRY);
2930

3031
if (EsqlCapabilities.Cap.TERM_FUNCTION.isEnabled()) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363

6464
/**
6565
* Full text function that performs a {@link QueryStringQuery} .
66+
* Unlike other ESQL functions, Match is both a function and an operator. This class provides implementation for both,
67+
* but the operator documentation is generated in {@link MatchOperator}.
6668
*/
6769
public class Match extends FullTextFunction implements PostOptimizationVerificationAware {
6870

@@ -101,7 +103,6 @@ public class Match extends FullTextFunction implements PostOptimizationVerificat
101103

102104
@FunctionInfo(
103105
returnType = "boolean",
104-
operator = ":",
105106
preview = true,
106107
description = """
107108
Use `MATCH` to perform a <<query-dsl-match-query,match query>> on the specified field.
@@ -136,7 +137,7 @@ public Match(Source source, Expression field, Expression matchQuery, QueryBuilde
136137
this.field = field;
137138
}
138139

139-
private static Match readFrom(StreamInput in) throws IOException {
140+
protected static Match readFrom(StreamInput in) throws IOException {
140141
Source source = Source.readFrom((PlanStreamInput) in);
141142
Expression field = in.readNamedWriteable(Expression.class);
142143
Expression query = in.readNamedWriteable(Expression.class);
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.expression.function.fulltext;
9+
10+
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
11+
import org.elasticsearch.common.io.stream.StreamInput;
12+
import org.elasticsearch.xpack.esql.core.expression.Expression;
13+
import org.elasticsearch.xpack.esql.core.tree.Source;
14+
import org.elasticsearch.xpack.esql.expression.function.Example;
15+
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
16+
import org.elasticsearch.xpack.esql.expression.function.Param;
17+
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
18+
19+
import java.io.IOException;
20+
21+
/**
22+
* This class exists to generate documentation for the match operator.
23+
* Unlike other ESQL functions, Match is both a function and an operator. This class provides the documentation for the operator.
24+
*/
25+
public class MatchOperator extends Match {
26+
27+
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "MatchOperator",
28+
MatchOperator::readFrom);
29+
30+
@FunctionInfo(
31+
returnType = "boolean",
32+
operator = ":",
33+
preview = true,
34+
description = """
35+
Use the match operator (`:`) to perform a <<query-dsl-match-query,match query>> on the specified field.
36+
Using `:` is equivalent to using the `match` query in the Elasticsearch Query DSL.
37+
38+
The match operator is equivalent to the <<esql-match,match function>>.
39+
40+
For using the function syntax, or adding <<match-field-params,match query parameters>>, you can use the
41+
<<esql-match,match function>>.
42+
43+
`:` returns true if the provided query matches the row.""",
44+
examples = { @Example(file = "match-function", tag = "match-with-field") }
45+
)
46+
public MatchOperator(
47+
Source source,
48+
@Param(
49+
name = "field",
50+
type = { "keyword", "text", "boolean", "date", "date_nanos", "double", "integer", "ip", "long", "unsigned_long", "version" },
51+
description = "Field that the query will target."
52+
) Expression field,
53+
@Param(
54+
name = "query",
55+
type = { "keyword", "boolean", "date", "date_nanos", "double", "integer", "ip", "long", "unsigned_long", "version" },
56+
description = "Value to find in the provided field."
57+
) Expression matchQuery
58+
) {
59+
super(source, field, matchQuery);
60+
}
61+
62+
protected static Match readFrom(StreamInput in) throws IOException {
63+
Source source = Source.readFrom((PlanStreamInput) in);
64+
Expression field = in.readNamedWriteable(Expression.class);
65+
Expression query = in.readNamedWriteable(Expression.class);
66+
67+
return new MatchOperator(source, field, query);
68+
}
69+
70+
@Override
71+
public String getWriteableName() {
72+
return ENTRY.name;
73+
}
74+
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/AbstractFunctionTestCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.elasticsearch.xpack.esql.evaluator.EvalMapper;
4646
import org.elasticsearch.xpack.esql.evaluator.mapper.EvaluatorMapper;
4747
import org.elasticsearch.xpack.esql.expression.function.fulltext.Match;
48+
import org.elasticsearch.xpack.esql.expression.function.fulltext.MatchOperator;
4849
import org.elasticsearch.xpack.esql.expression.function.scalar.conditional.Greatest;
4950
import org.elasticsearch.xpack.esql.expression.function.scalar.nulls.Coalesce;
5051
import org.elasticsearch.xpack.esql.expression.function.scalar.string.RLike;
@@ -139,7 +140,7 @@ public abstract class AbstractFunctionTestCase extends ESTestCase {
139140
entry("is_null", IsNull.class),
140141
entry("is_not_null", IsNotNull.class),
141142
// Match operator is both a function and an operator
142-
entry("match_operator", Match.class)
143+
entry("match_operator", MatchOperator.class)
143144
);
144145

145146
private static EsqlFunctionRegistry functionRegistry = new EsqlFunctionRegistry().snapshotRegistry();

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/fulltext/MatchOperatorTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
import com.carrotsearch.randomizedtesting.annotations.Name;
1111
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
1212

13+
import org.elasticsearch.xpack.esql.core.expression.Expression;
14+
import org.elasticsearch.xpack.esql.core.tree.Source;
1315
import org.elasticsearch.xpack.esql.expression.function.FunctionName;
1416
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
1517

18+
import java.util.List;
1619
import java.util.function.Supplier;
1720

1821
/**
@@ -29,4 +32,9 @@ public MatchOperatorTests(@Name("TestCase") Supplier<TestCaseSupplier.TestCase>
2932
public static Iterable<Object[]> parameters() {
3033
return MatchTests.parameters();
3134
}
35+
36+
@Override
37+
protected Expression build(Source source, List<Expression> args) {
38+
return new MatchOperator(source, args.get(0), args.get(1));
39+
}
3240
}

0 commit comments

Comments
 (0)