Kusto:使用解析运算符时删除不匹配的行

Kusto: remove non-matching rows when using the parse operator

我正在使用 Kusto 查询 Azure 日志分析,并使用 parse 运算符提取字段,然后仅保留正确解析的记录:

traces
| parse message with "Search found " people " people in " groupCount " groups"
| where people != "" and groupCount != ""
| order by n desc

是否有更简洁的方法来解析和删除不匹配的行?如果我从一组日志中解析出很多列,可能包含部分匹配项,那么 parsewhere 之间的这种联系就会变得很复杂。

相比之下,在 SumoLogic 中,parse 运算符会自动删除所有与解析模式不匹配的行,这使得管道非常整洁:

*
| parse "Search found * people in * groups" as people, groupCount
| order by n desc

在 Kusto 中:'parse' 运算符不会自动筛选与提供的模式不匹配的行,运算符的工作方式与 'extend' 模式相同 - 添加更多列。 如果您想过滤特定行 - 建议在 'parse' 之前使用 'where' 运算符:这也会提高性能,因为 'parse' 将扫描更少的行。

traces
| where message startswith 'Search found'
| parse message with "Search found " people " people in " groupCount " groups"
 ...

现在有一个内置运算符可以执行此操作:parse-where

https://docs.microsoft.com/en-us/azure/kusto/query/parsewhereoperator

它的语法与 parse 类似,但将从其输出中忽略任何与解析模式不匹配的记录。

所以查询:

traces
| parse message with "Search found " people " people in " groupCount " groups"
| where people != "" and groupCount != ""
| order by n desc

变为:

traces
| parse-where message with "Search found " people " people in " groupCount " groups"
| order by n desc