繁体   English   中英

Kusto(Azure Application Insights):如何根据初始搜索查询的结果集中的值查询结果?

[英]Kusto (with Azure Application Insights): How can I query results based on values in a result set from an initial search query?

我有一种情况,一个实体可以有多个与之关联的 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 上的跟踪,右侧不是null,然后我合并结果。

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

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

你可以这样做:

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失败并显示“搜索表达式的模式必须是常量字符串”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM