You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何不使用正则表达式从请求URL提取foo-id与bar-id字段?

不用正则表达式提取URL路径中的foo-id和bar-id

当然可以解决!既然你已经通过parse_url拿到了请求路径,我们完全可以用Kusto的split()函数来拆分路径字符串,避开正则表达式也能精准提取目标ID。

完整查询示例

requests
| where timestamp > ago(1d)
| extend parsed_url = parse_url(url)
| extend path = tostring(parsed_url["Path"])
// 将路径按斜杠拆分为字符串数组
| extend path_parts = split(path, "/")
// 提取foo-id:对应数组索引3的元素(路径结构为/api/foos/{foo-id}/...,拆分后第4段)
| extend foo_id = tostring(path_parts[3])
// 提取bar-id:对应数组索引5的元素(路径结构为.../bars/{bar-id}/...,拆分后第6段)
| extend bar_id = tostring(path_parts[5])
// 可选:过滤掉不符合目标路径结构的请求,避免无效值
| where array_length(path_parts) >= 6 
  and path_parts[2] == "foos" 
  and path_parts[4] == "bars"
// 选择需要展示的列
| project timestamp, url, foo_id, bar_id

关键逻辑说明

  • split(path, "/")会把你的路径(比如/api/foos/123/bars/456/details)拆分成这样的数组:["", "api", "foos", "123", "bars", "456", "details"]
  • 不管路径后面有没有额外的子段(比如/details),foo-id始终在数组的第4个位置(索引3),bar-id始终在第6个位置(索引5)
  • 最后的where条件是可选但推荐的:它会过滤掉那些不符合/api/foos/{foo-id}/bars/{bar-id}结构的请求,确保你提取的都是有效的ID值

内容的提问来源于stack exchange,提问作者Bernard Vander Beken

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 14:02:48