Skip to content

arrayContains - Test if array contains element

The arrayContains function checks if a given element exists in an array.

Syntax

arrayContains(array: array<T>, element: T): bool

Arguments

Name Type Required Description
array array of type T true T must be either string, bool, number, interval, timestamp, regexp or enum
element T true T must be either string, bool, number, interval, timestamp, regexp or enum

Example - Check if a particular IP appears in a block list

Consider the following log, from a firewall:

{
    "action": "BLOCK",
    "client_ip": "134.56.32.98",
    "blocked_ips": [
        "134.56.32.91",
        "134.56.32.93",
        "134.56.32.90",
        "134.56.32.105"
    ]
}

We can see that the firewall blocked a given IP address. If we want to check our client_ip against the block list, we can do this using arrayContains:

create is_blocked_ip from blocked_ips.arrayContains(client_ip)

This will create a field, is_blocked_ip that is true if the client_ip field appears in the blocked_ips list, otherwise false.