Skip to main content
Version: 6.0

format

Description

Converts the results from the previous part of a search query into a logical expression for further search. Converts the results of the previous part of the search query into a logical expression for searching. Used inside the subquery search [ ... | format ] to dynamically form a filter condition based on data from another source.

Please note!

Avoid forming excessively long search query strings after formatting the query. This may exceed the maxClauseCount limit in SA Data Storage and cause a query execution error.


Syntax

| format

Query Examples

Example 1

In this example, format converts a list of users from the zabbix index matching the pattern Iv* into a logical expression. This expression is then applied as a filter condition in active_directory - as a result, only events where the user field matches the found values remain.

Index zabbix:

@timestampuser
2026-06-24T10:00:00ZIvanov
2026-06-24T10:01:00ZIvanenko
2026-06-24T10:02:00ZPetrov
2026-06-24T10:03:00ZSidorov

Index active_directory:

@timestampuserdepartmenthost
2026-06-24T10:00:00ZIvanovITpc-01
2026-06-24T10:01:00ZIvanenkoHRpc-02
2026-06-24T10:02:00ZPetrovFinancepc-03
2026-06-24T10:03:00ZSidorovITpc-04
source active_directory | search [ source zabbix | search user="Iv*" | fields user | format]

format forms an expression like (user="Ivanov" OR user="Ivanenko") from the subquery results. Petrov and Sidorov do not appear in the result because they don't match the Iv* pattern:

@timestampuserdepartmenthost
2026-06-24T10:00:00ZIvanovITpc-01
2026-06-24T10:01:00ZIvanenkoHRpc-02

Example 2

In this example, format forms a search condition based on a calculated value. makeresults creates one row, eval calculates round(pi()) = 3 and writes the result to the id field. The format command converts this into an expression (id=3), which is used to filter the users index.

Index users:

@timestampidnamerole
2026-06-24T10:00:00Z1Aliceviewer
2026-06-24T10:01:00Z2Bobeditor
2026-06-24T10:02:00Z3Charlieadmin
2026-06-24T10:03:00Z4Daveviewer
source users
| search
[ | makeresults
| eval id=round(pi())
| fields id
| format ]

As a result, only the record with id = 3 is returned:

@timestampidnamerole
2026-06-24T10:02:00Z3Charlieadmin

Example 3

In this example, components DC are extracted from the distinguishedname field in the ad_computer index using rex, then joined with dots by the eval command. The resulting domainUser value forms a search condition through format, which is applied to the ad_users index - only users from the vv.local domain remain.

Index ad_computer:

@timestampdistinguishedname
2026-06-24T10:00:00ZCN=Ivanov Ivan,OU=Employees, DC=vv,DC=local
2026-06-24T10:01:00ZCN=Petrov Petr,OU=Employees, DC=vv,DC=local
Index ad_users:
@timestampdomainUser
------
2026-06-24T10:00:00Zvv.local
2026-06-24T10:01:00Zvv.local
2026-06-24T10:02:00Zother.domain
source ad_users
| search
[ source ad_computer
| rex field=distinguishedname "DC=(?<DC>[a-z]*)" max_match=0
| eval domainUser=mvjoin(DC, ".")
| stats count by domainUser
| fields domainUser
| format ]

rex extracts DC components (vv and local), mvjoin assembles them into the string vv.local, format forms the expression (domainUser="vv.local"). User smith from the other.domain domain does not appear in the result:

@timestampdomainUserlogindepartment
2026-06-24T10:00:00Zvv.localivanovIT
2026-06-24T10:01:00Zvv.localpetrovFinance