本文主要介紹控制指令的用法和樣本。
.let
定義命名資料集,作為後續SPL運算式的輸入。SPL資料集詳情請參見SPL資料集。
文法
.let <dataset>=<spl-expr>參數說明
參數 | 類型 | 必填 | 說明 |
dataset | String | 是 | 資料集名稱,包含字母、數字和底線,並且以字母開頭,區分大小寫。 |
spl-expr | SPLExp | 是 | 產生資料集的SPL運算式。 |
樣本
將訪問日誌基於狀態代碼進行過濾和分類處理,然後將其輸出。
SPL語句
-- SPL處理結果定義為命名資料集src,作為後續SPL運算式的輸入 .let src = * | where status=cast(status as BIGINT); -- 以命名資料集src作為輸入,篩選status欄位為5xx的資料,定義資料集err,不輸出 .let err = $src | where status >= 500 | extend msg='ERR'; -- 以命名資料集src作為輸入,篩選status欄位為2xx的資料,定義資料集ok,不輸出 .let ok = $src | where status >= 200 and status < 300 | extend msg='OK'; -- 輸出命名資料集err和ok $err; $ok;輸入資料
# 條目1 status: '200' body: 'this is a test' # 條目2 status: '500' body: 'internal error' # 條目3 status: '404' body: 'not found'輸出結果
# 條目1: 資料集為err status: '500' body: 'internal error' msg: 'ERR' # 條目2: 資料集為ok status: '200' body: 'this is a test' msg: 'OK'