Skip to content

Commit 726d87c

Browse files
committed
Add examples and docs for function named parameters
1 parent 33dd062 commit 726d87c

File tree

8 files changed

+101
-11
lines changed

8 files changed

+101
-11
lines changed

docs/reference/esql/esql-syntax.asciidoc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,48 @@ Timespan literals are not whitespace sensitive. These expressions are all valid:
169169
* `1 day`
170170
* `1 day`
171171

172+
[discrete]
173+
[[esql-function-named-params]]
174+
==== Function named parameters
175+
176+
Some functions like <<esql-match,match>> use named parameters to provide additional options.
177+
178+
Named parameters allow specifying name value pairs, using the following syntax:
179+
180+
`{"option_name": option_value, "another_option_name": another_value}`
181+
182+
Valid value types are strings, numbers and booleans.
183+
184+
An example using <<esql-match,match>>:
185+
186+
[source,console]
187+
----
188+
POST /_query
189+
{
190+
"query": """
191+
FROM library
192+
| WHERE match(author, "Frank Herbert", {"minimum_should_match": 2, "operator": "AND"})
193+
"""
194+
}
195+
----
196+
// TEST[setup:library]
197+
198+
You can also use <<esql-rest-params,query parameters>> in function named parameters:
199+
200+
[source,console]
201+
----
202+
POST /_query
203+
{
204+
"query": """
205+
FROM library
206+
| EVAL year = DATE_EXTRACT("year", release_date)
207+
| WHERE page_count > ? AND match(author, ?, {"minimum_should_match": ?})
208+
| STATS count = COUNT(*) by year
209+
| WHERE count > ?
210+
| LIMIT 5
211+
""",
212+
"params": [300, "Frank Herbert", 2]
213+
}
214+
----
215+
// TEST[setup:library]
216+

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

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/examples/match.asciidoc

Lines changed: 9 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/kibana/definition/match.json

Lines changed: 4 additions & 3 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: 27 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/types/match_operator.asciidoc

Lines changed: 2 additions & 1 deletion
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: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,13 +694,17 @@ testMatchWithOptionsOperator
694694
required_capability: match_function
695695
required_capability: match_function_options
696696

697-
from books
698-
| where match(title, "Hobbit Back Again", {"operator": "AND"})
699-
| keep title;
697+
// tag::match-with-named-function-params[]
698+
FROM books
699+
| WHERE MATCH(title, "Hobbit Back Again", {"operator": "AND"})
700+
| KEEP title;
701+
// end::match-with-named-function-params[]
700702

703+
// tag::match-with-named-function-params-result[]
701704
title:text
702705
The Hobbit or There and Back Again
703706
;
707+
// end::match-with-named-function-params-result[]
704708

705709
testMatchWithOptionsMinimumShouldMatch
706710
required_capability: match_function

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,15 @@ public class Match extends FullTextFunction implements PostOptimizationVerificat
156156
Match can be used on fields from the text family like <<text, text>> and <<semantic-text, semantic_text>>,
157157
as well as other field types like keyword, boolean, dates, and numeric types.
158158
159+
Match can use <<esql-function-named-params,function named parameters>> to specify additional options for the match query.
160+
All <<match-field-params,match query parameters>> are supported.
161+
159162
For a simplified syntax, you can use the <<esql-search-operators,match operator>> `:` operator instead of `MATCH`.
160163
161164
`MATCH` returns true if the provided query matches the row.""",
162-
examples = { @Example(file = "match-function", tag = "match-with-field") }
165+
examples = {
166+
@Example(file = "match-function", tag = "match-with-field"),
167+
@Example(file = "match-function", tag = "match-with-named-function-params") }
163168
)
164169
public Match(
165170
Source source,

0 commit comments

Comments
 (0)