Available:neighbor() v1.174.0

The neighbor() function is available from version 1.174.0.

The neighbor() function allows access to fields from a single neighboring event in a sequence. It retrieves fields from either a preceding or succeeding event at a specified distance from the current event. The neighbor() function is particularly useful for comparing events or detecting patterns in sequential data.

For more information about sequence functions and combined usage, see Sequence Query Functions.

ParameterTypeRequiredDefault ValueDescription
directionenumoptional[a] preceding Specifies whether to look at preceding or succeeding events.
   Valid Values
   precedingLook at preceding events
   succeedingLook at succeeding events
distanceintegeroptional[a] 1 The number of events to look ahead or behind.
  Maximum1000010,000 events
include[b]array of stringsrequired   The fields to include from the neighboring event.
prefixstringoptional[a]   A prefix to add to the included field names to distinguish them from the current event's fields.

[a] Optional parameters use their default value unless explicitly set.

[b] The parameter name include can be omitted.

Hide omitted argument names for this function

Show omitted argument names for this function

Note

  • The neighbor() function must be used after an aggregator function (for example, head(), sort(), bucket(), groupBy() timeChart()) to ensure event ordering, as the neighbor() function requires a specific order to calculate cumulative values correctly.

  • The neighbor can be found a maximum of 10,000 events away.

neighbor() Examples

Click + next to an example below to get the full details.

Access Fields From Single Neighboring Event in a Sequence - Example 1

Access fields from a single neighboring (preceeding) event in a sequence using the neighbor() function

Access Fields From Single Neighboring Event in a Sequence - Example 2

Access fields from a single neighboring (succeeding) event in a sequence using the neighbor() function

Access Fields From Single Neighboring Event in a Sequence - Example 3

Access fields from a single neighboring (further away) event in a sequence using the neighbor() function

Count Events Within Partitions Based on Condition

Count events within partitions based on a specific condition using the partition() function combined with neighbor() and accumulate()

Detect Changes And Compute Differences Between Events - Example 1

Detect changes and compute differences between events using the neighbor() function

Detect Changes And Compute Differences Between Events - Example 2

Detect changes and compute differences between events using the neighbor() function combined with accumulate()

Detect Continuously Upwards Going Trend

Detect continuously upwards going trend using the slidingWindow() function combined with neighbor()