Skip to content

Commit 7860ad1

Browse files
committed
Add parameter information to docs
1 parent c3d961d commit 7860ad1

File tree

12 files changed

+361
-125
lines changed

12 files changed

+361
-125
lines changed

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

Lines changed: 194 additions & 16 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: 3 additions & 27 deletions
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: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/layout/match.asciidoc

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/esql/functions/types/match.asciidoc

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

docs/reference/esql/functions/types/match_operator.asciidoc

Lines changed: 1 addition & 2 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-function.csv-spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,8 @@ FROM books
703703
// tag::match-with-named-function-params-result[]
704704
title:text
705705
The Hobbit or There and Back Again
706-
;
707706
// end::match-with-named-function-params-result[]
707+
;
708708

709709
testMatchWithOptionsMinimumShouldMatch
710710
required_capability: match_function

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,31 +183,37 @@ public Match(
183183
params = {
184184
@MapParam.MapParamEntry(
185185
name = "analyzer",
186+
type = "keyword",
186187
valueHint = { "standard" },
187188
description = "Analyzer used to convert the text in the query value into token."
188189
),
189190
@MapParam.MapParamEntry(
190191
name = "auto_generate_synonyms_phrase_query",
192+
type = "boolean",
191193
valueHint = { "true", "false" },
192194
description = "If true, match phrase queries are automatically created for multi-term synonyms."
193195
),
194196
@MapParam.MapParamEntry(
195197
name = "fuzziness",
198+
type = "keyword",
196199
valueHint = { "AUTO", "1", "2" },
197200
description = "Maximum edit distance allowed for matching."
198201
),
199202
@MapParam.MapParamEntry(
200203
name = "boost",
204+
type = "float",
201205
valueHint = { "2.5" },
202206
description = "Floating point number used to decrease or increase the relevance scores of the query."
203207
),
204208
@MapParam.MapParamEntry(
205209
name = "fuzzy_transpositions",
210+
type = "boolean",
206211
valueHint = { "true", "false" },
207212
description = "If true, edits for fuzzy matching include transpositions of two adjacent characters (ab → ba)."
208213
),
209214
@MapParam.MapParamEntry(
210215
name = "fuzzy_rewrite",
216+
type = "keyword",
211217
valueHint = {
212218
"constant_score_blended",
213219
"constant_score",
@@ -219,27 +225,32 @@ public Match(
219225
),
220226
@MapParam.MapParamEntry(
221227
name = "lenient",
228+
type = "boolean",
222229
valueHint = { "true", "false" },
223230
description = "If false, format-based errors, such as providing a text query value for a numeric field, are returned."
224231
),
225232
@MapParam.MapParamEntry(
226233
name = "max_expansions",
234+
type = "integer",
227235
valueHint = { "50" },
228236
description = "Maximum number of terms to which the query will expand."
229237
),
230238
@MapParam.MapParamEntry(
231239
name = "minimum_should_match",
240+
type = "integer",
232241
valueHint = { "2" },
233242
description = "Minimum number of clauses that must match for a document to be returned."
234243
),
235244
@MapParam.MapParamEntry(
236245
name = "operator",
246+
type = "keyword",
237247
valueHint = { "AND", "OR" },
238248
description = "Boolean logic used to interpret text in the query value"
239249
),
240250
@MapParam.MapParamEntry(name = "prefix_length", valueHint = { "1" }, description = ""),
241251
@MapParam.MapParamEntry(
242252
name = "zero_terms_query",
253+
type = "keyword",
243254
valueHint = { "none", "all" },
244255
description = "Number of beginning characters left unchanged for fuzzy matching."
245256
) },

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

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
import java.util.List;
9191
import java.util.Locale;
9292
import java.util.Map;
93+
import java.util.Optional;
9394
import java.util.Set;
9495
import java.util.TreeSet;
9596
import java.util.stream.Collectors;
@@ -926,9 +927,17 @@ public static void renderDocs() throws IOException {
926927
renderParametersList(description.argNames(), description.argDescriptions());
927928
FunctionInfo info = EsqlFunctionRegistry.functionInfo(definition);
928929
renderDescription(description.description(), info.detailedDescription(), info.note());
930+
Optional<EsqlFunctionRegistry.ArgSignature> mapArgSignature = description.args()
931+
.stream()
932+
.filter(EsqlFunctionRegistry.ArgSignature::mapArg)
933+
.findFirst();
934+
boolean hasFunctionOptions = mapArgSignature.isPresent();
935+
if (hasFunctionOptions) {
936+
renderFunctionNamedParams((EsqlFunctionRegistry.MapArgSignature) mapArgSignature.get());
937+
}
929938
boolean hasExamples = renderExamples(info);
930939
boolean hasAppendix = renderAppendix(info.appendix());
931-
renderFullLayout(name, info.preview(), hasExamples, hasAppendix);
940+
renderFullLayout(name, info.preview(), hasExamples, hasAppendix, hasFunctionOptions);
932941
renderKibanaInlineDocs(name, info);
933942
renderKibanaFunctionDefinition(name, info, description.args(), description.variadic());
934943
return;
@@ -947,8 +956,11 @@ public static void renderDocs() throws IOException {
947956
private static void renderTypes(List<EsqlFunctionRegistry.ArgSignature> args) throws IOException {
948957
StringBuilder header = new StringBuilder();
949958
List<String> argNames = args.stream().map(EsqlFunctionRegistry.ArgSignature::name).toList();
950-
for (String arg : argNames) {
951-
header.append(arg).append(" | ");
959+
for (EsqlFunctionRegistry.ArgSignature arg : args) {
960+
if (arg.optional()) {
961+
header.append("(optional) ");
962+
}
963+
header.append(arg.name()).append(" | ");
952964
}
953965
header.append("result");
954966

@@ -962,12 +974,15 @@ private static void renderTypes(List<EsqlFunctionRegistry.ArgSignature> args) th
962974
}
963975
StringBuilder b = new StringBuilder();
964976
for (int i = 0; i < sig.getKey().size(); i++) {
977+
965978
DataType argType = sig.getKey().get(i);
966-
if (args.get(i).mapArg()) {
967-
b.append("map | ");
979+
EsqlFunctionRegistry.ArgSignature argSignature = args.get(i);
980+
if (argSignature.mapArg()) {
981+
b.append("named parameters");
968982
} else {
969-
b.append(argType.esNameIfPossible()).append(" | ");
983+
b.append(argType.esNameIfPossible());
970984
}
985+
b.append(" | ");
971986
}
972987
b.append("| ".repeat(argNames.size() - sig.getKey().size()));
973988
b.append(sig.getValue().esNameIfPossible());
@@ -988,6 +1003,27 @@ private static void renderTypes(List<EsqlFunctionRegistry.ArgSignature> args) th
9881003
writeToTempDir("types", rendered, "asciidoc");
9891004
}
9901005

1006+
private static void renderFunctionNamedParams(EsqlFunctionRegistry.MapArgSignature mapArgSignature) throws IOException {
1007+
String header = "name | types | description";
1008+
1009+
List<String> table = new ArrayList<>();
1010+
for (Map.Entry<String, EsqlFunctionRegistry.MapEntryArgSignature> argSignatureEntry : mapArgSignature.mapParams().entrySet()) {
1011+
StringBuilder builder = new StringBuilder();
1012+
EsqlFunctionRegistry.MapEntryArgSignature arg = argSignatureEntry.getValue();
1013+
builder.append(arg.name()).append(" | ").append(arg.type()).append(" | ").append(arg.description());
1014+
table.add(builder.toString());
1015+
}
1016+
1017+
String rendered = DOCS_WARNING + """
1018+
*Supported function named parameters*
1019+
1020+
[%header.monospaced.styled,format=dsv,separator=|]
1021+
|===
1022+
""" + header + "\n" + table.stream().collect(Collectors.joining("\n")) + "\n|===\n";
1023+
LogManager.getLogger(getTestClass()).info("Writing function named parameters for [{}]:\n{}", functionName(), rendered);
1024+
writeToTempDir("functionNamedParams", rendered, "asciidoc");
1025+
}
1026+
9911027
private static void renderParametersList(List<String> argNames, List<String> argDescriptions) throws IOException {
9921028
StringBuilder builder = new StringBuilder();
9931029
builder.append(DOCS_WARNING);
@@ -1068,7 +1104,8 @@ private static boolean renderAppendix(String appendix) throws IOException {
10681104
return true;
10691105
}
10701106

1071-
private static void renderFullLayout(String name, boolean preview, boolean hasExamples, boolean hasAppendix) throws IOException {
1107+
private static void renderFullLayout(String name, boolean preview, boolean hasExamples, boolean hasAppendix, boolean hasFunctionOptions)
1108+
throws IOException {
10721109
String rendered = DOCS_WARNING + """
10731110
[discrete]
10741111
[[esql-$NAME$]]
@@ -1085,6 +1122,13 @@ private static void renderFullLayout(String name, boolean preview, boolean hasEx
10851122
""".replace("$NAME$", name)
10861123
.replace("$UPPER_NAME$", name.toUpperCase(Locale.ROOT))
10871124
.replace("$PREVIEW_CALLOUT$", preview ? PREVIEW_CALLOUT : "");
1125+
if (hasFunctionOptions) {
1126+
rendered += "ifeval::[\"{release-state}\"==\"unreleased\"]\n"
1127+
+ "//include::../optionalFunctionParams/"
1128+
+ name
1129+
+ ".asciidoc[]\n"
1130+
+ "endif::[]\n";
1131+
}
10881132
if (hasExamples) {
10891133
rendered += "include::../examples/" + name + ".asciidoc[]\n";
10901134
}

0 commit comments

Comments
 (0)