0

我有一种情况,一个实体可以有多个与之关联的 id,比如 ID1 和 ID2,我登录到应用洞察,有时记录有 customDimensions.ID1 值,有时它们有 customDimensions.ID2 值,有时它们有两个值。

因此,当我想确定实体 ID1=123 发生了什么时,我运行一个初始查询来确定另一个 ID / ID2 值是什么,然后我运行一个查询来获取包含 ID1 或 ID2 的记录。

给定 ID1="123" 我从以下内容开始:


    traces 
    | where tostring(customDimensions.ID1) == "123"
    | project
      ID1 = tostring(customDimensions.ID1)
      , ID2 = tostring(customDimensions.ID2)
      , message

结果看起来像:

|ID1|ID2|messsage|
|---|---|--------|
|123||this record doesn't have a second id value|
|123|456|this log record has the other id value that I want to use|
|123||another message|

在这些结果中,我得到这个 ID2 值“456”,并在另一个查询中使用它:


    traces 
    | where tostring(customDimensions.ID1) == "123" or tostring(customDimensions.ID2) == "456" or 
    | project
    ID1 = tostring(customDimensions.ID1)
    , ID2 = tostring(customDimensions.ID2)
    , message

我得到了更多的记录:

|ID1|ID2|messsage|
|---|---|--------|
|123||this log record doesn't have the second id|
|123|456|this log record has other id value that I want to use|
|123||another message|
||456|this record doesn't have ID1, but it has ID2|
||456|again, only has second ID|

我希望有一种聪明的方法可以一步/一个查询来完成。

它也不必是完美的,我可以做出一些假设,例如 ID1 只会与另一个 ID2 值相关联(不包括 null / 空字符串)

如果没有连接,使用我想象的 GET-FIRST-VALUE-OF-RESULT() 方法,我认为解决方案可能类似于:


    let myID1 = "123";
    let myID2 = GET-FIRST-VALUE-OF-FIRST-COL-OF-RESULT-SET(
      traces 
      | where * has myID1 
      | where tostring(customDimensions.ID2) != ""
      | project tostring(customDimensions.ID2)
    );
    traces
    | where * has myID1 or * has myID2

加入...我不知道。我正在尝试使用获取不同 ID1、ID2 值的查询来处理它,其中任何一个都包含我的搜索字符串,然后我有两个子查询将跟踪连接到 ID1 上的第一个结果集,然后在 ID2 上,其中右侧不为空,然后我合并结果。

但这感觉超级尴尬/闻起来很糟糕。我想有一种更简单的方法可以做到这一点。只是想总结一下 - 我想查询包含搜索字符串的记录,然后从一组customDimensions属性中提取一组不同的值,然后使用这些值来查询包含任何检索到的值的记录我最初的查询/查询。

抱歉,当我有机会时,我会更新一些示例数据和查询的开始。

4

1 回答 1

0

你可以这样做:

let myID1 = "123";
let myID2 = toscalar(
traces 
| where tostring(customDimensions.ID1) == myID1
| project ID2 = tostring(customDimensions.ID2)
| where ID2 != ""
| take 1);
traces
| project
    ID1 = tostring(customDimensions.ID1),
    ID2 = tostring(customDimensions.ID2),
    message
| where * has myID1 or ID2 in (myID2)

使用 in:可以很好地ID2 in (myID2)工作,但不适用于搜索表达式,因为 KQL 需要一个常量字符串。所以* has myID2失败了'搜索表达式的模式必须是一个常量字符串'

于 2021-10-08T07:46:11.860 回答