You need to enable JavaScript to run this app. 如何在Splunk中实现基于指定子串的去重搜索
优惠活动
大模型
产品
解决方案
定价
更多

如何在Splunk中实现基于指定子串的去重搜索

Splunk 按userCache后唯一值去重实现方案

你可以通过「字段提取+去重」的组合逻辑实现需求,完整查询语句如下:

host=node-1 AND "userCache:"
| rex "userCache:\s+(?<username>\S+)"
| dedup username
| table _time username host

各部分作用说明:

  • rex "userCache:\s+(?<username>\S+)":用正则从事件原文中匹配userCache:后面的内容,提取出用户名为自定义字段username,其中\s+匹配userCache:后连续的空格,\S+匹配连续的非空白字符即用户名。
  • dedup username:对提取到的username字段去重,每个用户名仅保留第一条匹配到的事件。
  • table _time username host为可选步骤,你可以按需调整展示的字段;如果需要保留完整原始事件,直接去掉该段即可。

如果你只需要获取所有唯一的用户名列表,不需要关联时间、主机等信息,可以用stats简化查询:

host=node-1 AND "userCache:"
| rex "userCache:\s+(?<username>\S+)"
| stats count by username
| fields - count

该写法会直接输出去重后的用户名列表,不携带原始事件的其他附加信息。

内容的提问来源于stack exchange,提问作者Tim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.09 18:54:03