整体说明
必要参数显⽰在尖括号 < > 中。
可选参数显⽰在⽅括号 [ ] 中。
table
在查询结果中只展示对应字段。
| table 字段1,字段2,字段3
stats
将查询结果进行聚合统计,类似 SQL 中的 group 。
| stats count by 字段1,字段2
说明
将查询结果按 字段1 和 字段2 分组,统计记录数量。
head
筛选出前10000条日志作为查询结果。
| head 10000
eval if in
| eval 新字段=if(字段 in ("甲","乙","丙"),"结果1","结果2")
说明
如果 字段 的值为"甲","乙","丙"中的任意一个,则 新字段 的值为"结果1",否则 新字段 的值为"结果2"。
iplocation
生成IP对应的地区信息,会在结果中加入 City、Country、lat、lon 和 Region 字段,用来表示日志中IP的所在地信息。
语法
iplocation [prefix=
示例
| iplocation lang=zh ip
| table Country,City,ip
tstats
对加速数据模型进行统计查询。
语法
| tstats [prestats=<bool>] [local=<bool>] [append=<bool>] [summariesonly=<bool>]
[allow_old_summaries=<bool>] [chunk_size=<unsigned int>] <stats-func>...
[FROM ( <namespace> | sid=<tscollect-job-id> | datamodel=<data_model-name> )]
[WHERE <search-query> | <field> IN (<value-list>)]
[BY <field-list> [span=<timespan>] ]
示例
| tstats summariesonly=t count from datamodel=数据模型名 where 1=1
rex
用正则表达式在某个字段中提取新字段。
语法
rex [field=<field>] ( <regex-expression> [max_match=<int>] [offset_field=<string>] ) |
(mode=sed <sed-expression>)
示例
| rex field=_raw "正则1(?<新字段名>正则2)正则3"
replace
将字段中的值替换为新值。
语法
replace (<wc-string> WITH <wc-string>)...[IN <field-list>]
示例
| replace "原值" with "新值" in 字段名
说明
原值中可以使用通配符 * 进行模糊匹配
earliest latest
将查询结果控制在某个时间范围。
一般用于子查询或动态查询。
示例
index=* earliest=-2h@h latest=now
说明
- 现在:now
- 2小时前:-2h@h
- 1天前:-1d@d