Skip to content

Commit 2405891

Browse files
authored
[ES|QL] Document return value for locate in case substring is not found (#112457)
* Document return value for locate in case substring is not found
1 parent 9a8d6fa commit 2405891

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
*Description*
44

5-
Returns an integer that indicates the position of a keyword substring within another string
5+
Returns an integer that indicates the position of a keyword substring within another string. Returns `0` if the substring cannot be found. Note that string positions start from `1`.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"comment" : "This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it.",
33
"type" : "eval",
44
"name" : "locate",
5-
"description" : "Returns an integer that indicates the position of a keyword substring within another string",
5+
"description" : "Returns an integer that indicates the position of a keyword substring within another string.\nReturns `0` if the substring cannot be found.\nNote that string positions start from `1`.",
66
"signatures" : [
77
{
88
"params" : [

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../READ
33
-->
44

55
### LOCATE
6-
Returns an integer that indicates the position of a keyword substring within another string
6+
Returns an integer that indicates the position of a keyword substring within another string.
7+
Returns `0` if the substring cannot be found.
8+
Note that string positions start from `1`.
79

x-pack/plugin/esql/qa/testFixtures/src/main/resources/meta.csv-spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ greatest |Returns the maximum value from many columns.
259259
least |Returns the minimum value from many columns.
260260
left |Returns the substring that extracts 'length' chars from 'string' starting from the left.
261261
length |Returns the character length of a string.
262-
locate |Returns an integer that indicates the position of a keyword substring within another string
262+
locate |Returns an integer that indicates the position of a keyword substring within another string. Returns `0` if the substring cannot be found. Note that string positions start from `1`.
263263
log |Returns the logarithm of a value to a base. The input can be any numeric value, the return value is always a double. Logs of zero, negative numbers, and base of one return `null` as well as a warning.
264264
log10 |Returns the logarithm of a value to base 10. The input can be any numeric value, the return value is always a double. Logs of 0 and negative numbers return `null` as well as a warning.
265265
ltrim |Removes leading whitespaces from a string.

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/Locate.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public class Locate extends EsqlScalarFunction implements OptionalArgument {
4040
private final Expression substr;
4141
private final Expression start;
4242

43-
@FunctionInfo(
44-
returnType = "integer",
45-
description = "Returns an integer that indicates the position of a keyword substring within another string"
46-
)
43+
@FunctionInfo(returnType = "integer", description = """
44+
Returns an integer that indicates the position of a keyword substring within another string.
45+
Returns `0` if the substring cannot be found.
46+
Note that string positions start from `1`.""")
4747
public Locate(
4848
Source source,
4949
@Param(name = "string", type = { "keyword", "text" }, description = "An input string") Expression str,

0 commit comments

Comments
 (0)