快速参考

SPL 语法速查与 SQL 概念对照

快速参考

概念对照

数据库概念SPL 概念说明
SQL 查询SPL 搜索检索事件,管道内过滤、转换、分组、统计
表搜索结果动态生成的行(事件)与列(字段)
表名index索引名
行事件通常对应一条带时间戳的日志
列字段字段集随语句与解析规则变化

从 SQL 到 SPL

意图SQL(示意)SPL(示意)
全表扫描SELECT * FROM mytableindex="mytable"
条件过滤WHERE col=5index="t" col=5 或 | where col=5
选列SELECT a, b| fields a, b 或 | table a, b
排序ORDER BY a DESC| sort - a
限制行数LIMIT 10| head 10 或 | limit 10
分组计数COUNT(*) GROUP BY user| stats count() by user
派生列lower(u) AS lu| eval lu=lower(u)
重命名AS| rename old as new
去重DISTINCT| dedup field
维表关联JOIN| lookup dim.csv key OUTPUT name

管道顺序(常用)

过滤事件
  → 裁剪 / 重命名字段
  → eval 派生
  → stats 聚合
  → lookup / iplocation  enrichment
  → sort / head / table 展示
index="firewall" action="deny"
| times earliest=-24h@h latest=now
| stats count() as hits by src_ip, dest_port
| sort - hits
| head 20
| lookup asset.csv ip as src_ip OUTPUT application_name

搜索条件操作符

操作符含义
= / ==等于
!= / <>不等于
< / <= / > / >=比较
like / not like模式匹配(% 多字符,_ 单字符)
AND / OR与 / 或(AND 优先;可用括号)

通配:* 零或多字符,? 单字符。

命令一览

命令用途
where管道内条件过滤
fields / table保留或输出字段
rename重命名
sort排序
eval派生字段
stats聚合
dedup去重
head / limit截取行
top / rare高频 / 低频值
lookup / inputlookup / outputlookup查找表
join / append / appendcols合并结果
iplocationIP 地理 enrichment
rex / parse / spath提取字段
makemv / mvexpand / mvcombine多值
fillnull / filldown / fillup空值处理
times语句内时间范围

On this page