【问题标题】:How to use Regex in kusto query如何在 kusto 查询中使用正则表达式
【发布时间】:2020-12-15 17:03:59
【问题描述】:

所以我有一个这样的 Kusto 查询

exceptions
| extend A_= tostring(customDimensions.A)
| where A_ in~ ("Could not get notes: From:", "failed to call", "Custom conference list" )
// | where A_ contains 'Could not get notes: From:' //This is working when I use "contains" operator but fails to check below 2 items when the first item doesn't exist
// | where A_ contains 'Custom conference list'
// | where A_ contains 'failed to call'

列表中的第一项是“Could not get notes: From:”,其中字符串末尾有多个 ID

例如;

无法获取注释:来自:abcd

无法获取注释:来自:abcdef

我要做的是获取所有以“无法获取注释:来自:”开头的项目,并在“in~”运算符中使用它们。

到目前为止,我已经尝试过使用如下所示的包含运算符

|where A_ contains 'Could not get notes: From:' // This seems to be working as it will outputting every item that starts with "Could not get notes: From:" but when I am trying to use it in the "in~" it is failing.

对每个唯一项目使用“包含”运算符的问题是,如果任何项目(比如 3 个项目)不存在,即使 2 个项目仍然存在,查询也不返回任何结果。

不确定这是否有更好的解决方案。

【问题讨论】:

    标签: azure-log-analytics azure-data-explorer kql


    【解决方案1】:

    你应该改用has_any

    exceptions
    | extend A_= tostring(customDimensions.A)
    | where A_ has_any ("Could not get notes: From:", "failed to call", "Custom conference list")
    

    另外,请注意containshas/has_any 慢得多,因为后者使用索引仅获取相关记录,而contains 扫描所有记录。但是请注意,两者之间存在语义差异:contains 查找子字符串,而 has 仅查找完整标记。例如,"hello world" contains "hell" 将返回 true,而 "hello world" has "hell" 将返回 false。在String Operators 文档中查看更多信息。

    【讨论】:

    • 刚刚找到解决方案。但是我不知道在速度方面哪个更好。非常感谢您的进一步解释@Slavik N
    猜你喜欢
    • 1970-01-01
    • 2013-04-27
    • 2011-07-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-02
    • 1970-01-01
    • 2011-04-29
    相关资源
    最近更新 更多