【问题标题】:Kusto (with Azure Application Insights): How can I query results based on values in a result set from an initial search query?Kusto(使用 Azure Application Insights):如何根据初始搜索查询的结果集中的值查询结果?
【发布时间】: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


    【解决方案1】:

    你可以这样做:

    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 失败,'搜索表达式的模式必须是一个常量字符串'

    【讨论】:

      猜你喜欢
      • 2022-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-10
      • 2011-03-22
      • 1970-01-01
      相关资源
      最近更新 更多