Route a single log entry to multiple storage destinations, with each destination receiving only the fields it needs. Use the tag-split-route pattern in data transformation to create independent copies of the original log before modifying fields.
Scenario
A raw log contains fields f1, f2, f3, f4, and f5. Each destination requires a different subset of these fields:
-
target1: Exclude f1 and f2. Retain f3, f4, and f5.
-
target2: Exclude f3 and f4. Retain f1, f2, and f5.
Solution overview
Export the same log to multiple destinations with different field sets by applying the tag-split-route pattern:
-
Tag -- Add a
tagfield to the log that lists all destination names. -
Split -- Split the log into separate copies, one per destination.
-
Route -- For each copy, drop the unwanted fields and send the log to the corresponding destination.
This pattern creates independent copies of the original log before applying any field-level modifications. Each destination receives exactly the fields it requires without affecting the other copies.
Configuration example
Raw log
__time__ : 1591754815
f1: GET
f2: https
f3: aliyun
f4: 200
f5: standard
Transformation rules
For more information about the data transformation functions used in this example, see Function overview.
The following rules implement the tag-split-route pattern:
-
Call
e_setto add atagfield with the valuetarget1, target2. -
Call
e_splitto split the log into two copies based on thetagfield. One copy containstag: target1, the other containstag: target2. -
For the
tag: target1copy, calle_composeinsidee_ifto drop fields f1 and f2, then send the result to target1 withe_output. Becausee_outputterminates processing for that copy, subsequent rules do not apply to it. -
For the
tag: target2copy (which continues to the next rule), drop fields f3 and f4, then send the result to target2 withe_output.
e_set("tag", "target1, target2")
e_split("tag")
e_if(e_search("tag==target1"), e_compose(e_drop_fields("f1", "f2", regex=False), e_output("target1")))
e_drop_fields("f3", "f4", regex=False)
e_output("target2")
Result for target1
__time__ : 1591754815
f3: aliyun
f4: 200
f5: standard
Result for target2
__time__ : 1591754815
f1: GET
f2: https
f5: standard
Common mistake: using e_coutput instead of e_output
The following transformation rules produce the correct output for target1 but cause data loss for target2:
e_drop_fields("f1", "f2", regex=False)
e_coutput("target1")
e_drop_fields("f3", "f4", regex=False)
e_output("target2")
Root cause
e_output terminates processing for the current log entry after sending it to a destination. In contrast, e_coutput sends a copy to the destination and continues executing subsequent rules on the already modified log.
In this example:
-
e_drop_fields("f1", "f2")removes f1 and f2 from the log. -
e_coutput("target1")sends the modified log (without f1 and f2) to target1 -- correct so far. -
Processing continues with the same modified log (f1 and f2 already removed).
-
e_drop_fields("f3", "f4")removes f3 and f4 from that modified log. -
e_output("target2")sends a log containing only f5 to target2 -- losing both f1 and f2.
Incorrect result for target2
__time__ : 1591754815
f5: standard
Expected fields f1 and f2 are missing because they were already dropped in step 1.
Fix
Use the tag-split-route pattern shown in the Configuration example section. This pattern creates independent copies of the original log before applying any field-level modifications, so each destination receives the correct field set.