@@ -10,6 +10,7 @@ experimental::[]
1010
1111* <<eql-fn-between>>
1212* <<eql-fn-endswith>>
13+ * <<eql-fn-indexof>>
1314* <<eql-fn-length>>
1415* <<eql-fn-startswith>>
1516* <<eql-fn-string>>
@@ -206,6 +207,114 @@ field datatypes:
206207*Returns:* boolean or `null`
207208====
208209
210+ [discrete]
211+ [[eql-fn-indexof]]
212+ === `indexOf`
213+
214+ Returns the first position of a provided substring in a source string.
215+
216+ If an optional start position is provided, this function returns the first
217+ occurrence of the substring at or after the start position.
218+
219+ [%collapsible]
220+ ====
221+ *Example*
222+ [source,eql]
223+ ----
224+ // url.domain = "subdomain.example.com"
225+ indexOf(url.domain, ".") // returns 9
226+ indexOf(url.domain, ".", 9) // returns 9
227+ indexOf(url.domain, ".", 10) // returns 17
228+ indexOf(url.domain, ".", -6) // returns 9
229+
230+ // empty strings
231+ indexOf("", "") // returns 0
232+ indexOf(url.domain, "") // returns 0
233+ indexOf(url.domain, "", 9) // returns 9
234+ indexOf(url.domain, "", 10) // returns 10
235+ indexOf(url.domain, "", -6) // returns 0
236+
237+ // missing substrings
238+ indexOf(url.domain, "z") // returns null
239+ indexOf(url.domain, "z", 9) // returns null
240+
241+ // start position is higher than string length
242+ indexOf(url.domain, ".", 30) // returns null
243+
244+ // null handling
245+ indexOf(null, ".", 9) // returns null
246+ indexOf(url.domain, null, 9) // returns null
247+ indexOf(url.domain, ".", null) // returns null
248+ ----
249+
250+ *Syntax*
251+ [source,txt]
252+ ----
253+ indexOf(<source>, <substring>[, <start_pos>])
254+ ----
255+
256+ *Parameters*
257+
258+ `<source>`::
259+ +
260+ --
261+ (Required, string or `null`)
262+ Source string. If `null`, the function returns `null`.
263+
264+ If using a field as the argument, this parameter supports only the following
265+ field datatypes:
266+
267+ * <<keyword,`keyword`>>
268+ * <<constant-keyword,`constant_keyword`>>
269+ * <<text,`text`>> field with a <<keyword,`keyword`>> or
270+ <<constant-keyword,`constant_keyword`>> sub-field
271+ --
272+
273+ `<substring>`::
274+ +
275+ --
276+ (Required, string or `null`)
277+ Substring to search for.
278+
279+ If this argument is `null` or the `<source>` string does not contain this
280+ substring, the function returns `null`.
281+
282+ If the `<start_pos>` is positive, empty strings (`""`) return the `<start_pos>`.
283+ Otherwise, empty strings return `0`.
284+
285+ If using a field as the argument, this parameter supports only the following
286+ field datatypes:
287+
288+ * <<keyword,`keyword`>>
289+ * <<constant-keyword,`constant_keyword`>>
290+ * <<text,`text`>> field with a <<keyword,`keyword`>> or
291+ <<constant-keyword,`constant_keyword`>> sub-field
292+ --
293+
294+ `<start_pos>`::
295+ +
296+ --
297+ (Optional, integer or `null`)
298+ Starting position for matching. The function will not return positions before
299+ this one. Defaults to `0`.
300+
301+ Positions are zero-indexed. Negative offsets are treated as `0`.
302+
303+ If this argument is `null` or higher than the length of the `<source>` string,
304+ the function returns `null`.
305+
306+ If using a field as the argument, this parameter supports only the following
307+ <<number,numeric>> field datatypes:
308+
309+ * `long`
310+ * `integer`
311+ * `short`
312+ * `byte`
313+ --
314+
315+ *Returns:* integer or `null`
316+ ====
317+
209318[discrete]
210319[[eql-fn-length]]
211320=== `length`
0 commit comments