Flow control functions determine how data transformation operations execute based on conditions. Use these functions to compose sequential operations, apply conditional logic, and route logs to different destinations.
Functions
|
Function |
Description |
|
Combines multiple operations into a sequence.
Supports combination with other functions. For more information, see Transform complex JSON data. |
|
|
Evaluates conditions and executes corresponding operations. Supports multiple condition-operation pairs.
This transformation rule is equivalent to the following Python code:
Supports combination with other functions. For more information, see Transform complex JSON data. |
|
|
Evaluates a condition and executes one of two operations based on the result.
This transformation rule is equivalent to the following Python code:
|
|
|
Evaluates multiple condition-operation pairs in sequence, similar to an if-elif-else chain.
This transformation rule is equivalent to the following Python code:
Supports combination with other functions. For more information, see Distribute data to multiple destination Logstores. |
e_compose
Combines multiple operations into a sequential pipeline.
-
Syntax
e_compose(Operation 1, Operation 2, ...) -
Parameters
Parameter Name
Type
Required
Description
Operation 1
Global processing function
Yes
One or more global processing functions.
Operation 2
Global processing function
No
One or more global processing functions.
-
Response
Returns the log after all operations are performed.
-
Examples
If the content field value is 123, delete the age and name fields and rename the content field to ctx.
-
Raw log
content: 123 age: 23 name: twiss -
Transformation rule
e_if( e_search("content==123"), e_compose(e_drop_fields("age|name"), e_rename("content", "ctx")), ) -
Result
ctx: 123
-
-
References
Supports combination with other functions. For more information, see Transform complex JSON data.
e_if
Evaluates conditions and executes corresponding operations.
-
Syntax
e_if(Condition, Operation) e_if(Condition 1, Operation 1, Condition 2, Operation 2, ...)NoteSpecify the
ConditionandOperationparameters in pairs. -
Parameters
Parameter Name
Type
Required
Description
Condition
Arbitrary
Yes
An expression or a combination of expressions. Non-Boolean results are evaluated for truthiness.
Operation
Global processing function
Yes
One or more global processing functions.
-
Response
Returns the log after the operations are performed.
-
Examples
-
Example 1: Match a field value and perform an operation.
If the result field value is failed or failure, set the __topic__ field to
login_failed_event.e_if(e_match("result", r"failed|failure"), e_set("__topic__", "login_failed_event")) -
Example 2: Extract data based on a field value.
If the request_body field exists and is not empty, use the e_json function to expand the request_body field value into multiple fields.
e_if(v("request_body"), e_json("request_body")) -
Example 3: Perform an advanced evaluation.
If the valid field value is failed in lowercase, discard the log.
e_if(op_eq(str_lower(v("valid")), "failed"), DROP) -
Example 4: Evaluate multiple conditions in sequence.
e_if(True, e_set("__topic__", "default_login"), e_match("valid", "failed"), e_set("__topic__", "login_failed_event") )
-
-
References
Supports combination with other functions. For more information, see Transform complex JSON data.
e_if_else
Evaluates a condition and executes one of two operations based on the result.
-
Syntax
e_if_else(Condition, Operation if true, Operation if false) -
Parameters
Parameter Name
Type
Required
Description
Condition
Arbitrary
Yes
An expression or a combination of expressions. Non-Boolean results are evaluated for truthiness.
Operation if true
Global processing function
Yes
One or more global processing functions.
Operation if false
Global processing function
Yes
One or more global processing functions.
-
Response
Returns the operation result that corresponds to the evaluated condition.
-
Examples
If the result field value is ok or pass, or the status field value is 200, retain the log. Otherwise, discard the log.
-
Raw log
result: ok status: 400result: Pass status: 200result: failure status: 500 -
Transformation rule
e_if_else( op_or(e_match("result", r"(?i)ok|pass"), e_search("status== 200")), KEEP, DROP ) -
Result: The first two logs are retained and the third log is discarded.
result: ok status: 400result: Pass status: 200
-
e_switch
Evaluates multiple condition-operation pairs in sequence, similar to an if-elif-else chain.
-
Syntax
e_switch(Condition 1, Operation 1, ..., default=None)NoteSpecify the
ConditionandOperationparameters in pairs. -
Parameters
Parameter Name
Type
Required
Description
Condition
Arbitrary
Yes
An expression or a combination of expressions. Non-Boolean results are evaluated for truthiness.
Operation
Global processing function
Yes
One or more global processing functions.
default
Global processing function
No
One or more global processing functions. Executes when no conditions are met.
-
Response
Returns the log after the matched operation is performed.
-
Examples
-
If the content field value is 123, set the __topic__ field to Number. If the data field value is 123, set the __topic__ field to PRO.
-
Raw log
__topic__: age: 18 content: 123 name: maki data: 342__topic__: age: 18 content: 23 name: maki data: 123 -
Transformation rule
e_switch( e_search("content==123"), e_set("__topic__", "Number", mode="overwrite"), e_search("data==123"), e_set("__topic__", "PRO", mode="overwrite"), ) -
Result
__topic__: Number age: 18 content: 123 name: maki data: 342__topic__: PRO age: 18 content: 23 name: maki data: 123
-
-
Combine e_switch with e_output to route logs that match specific rules to different Logstores. Set
default=e_drop()to discard logs that match no rules. If thedefaultparameter is not set, unmatched logs are delivered to the first configured Logstore.-
Raw log
__topic__: sas-log-dns test: aliyun __topic__: aegis-log-network test:ecs __topic__: local-dns test:sls __topic__: aegis-log-login test: sls -
Transformation rule
e_switch(e_match("__topic__","sas-log-dns"),e_output(name="target1"), e_match("__topic__","sas-log-process"),e_output(name="target2"), e_match("__topic__","local-dns"),e_output(name="target3"), e_match("__topic__","aegis-log-network"),e_output(name="target4"), e_match("__topic__","aegis-log-login"),e_output(name="target5"), default=e_drop())
-
-
-
References
Supports combination with other functions. For more information, see Distribute data to multiple destination Logstores.