【发布时间】:2021-11-23 13:27:18
【问题描述】:
我有一种情况,一个实体可以有多个关联的 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 属性中提取一组不同的值,然后使用这些值来查询包含任何从我的初始查询/查询中检索到值。
抱歉,有机会我会更新一些示例数据并开始查询。
【问题讨论】:
标签: azure-application-insights azure-data-explorer kql kusto-explorer