如何在subselect中使用过滤器

时间:2017-12-21 11:33:14

标签: azure azure-application-insights azure-log-analytics

我想对相关数据集执行子选择。需要使用主查询中的数据过滤该子数据:

customEvents
| extend envId = tostring(customDimensions.EnvironmentId)
| extend organisation = tostring(customDimensions.OrganisationName)
| extend version = tostring(customDimensions.Version)
| extend app = tostring(customDimensions.Appname)
| where customDimensions.EventName contains "ApiSessionStartStart"
| extend dbInfo = toscalar(
    customEvents 
    | extend dbInfo = tostring(customDimensions.dbInfo)
    | extend serverEnvId = tostring(customDimensions.EnvironmentId)
    | where customDimensions.EventName == "ServiceSessionStart" or customDimensions.EventName == "ServiceSessionContinuation"
    | where serverEnvId = envId // This gives and error
    | project dbInfo
    | take 1)
| order by timestamp desc
| project timestamp, customDimensions.OrganisationName, customDimensions.Version, customDimensions.onBehalfOf, customDimensions.userId, customDimensions.Appname, customDimensions.apiKey, customDimensions.remoteIp, session_Id , dbInfo,  envId

上述查询导致错误:

  

无法解析实体'envId'

如何根据主查询中的字段envId过滤子选择中的数据?

1 个答案:

答案 0 :(得分:1)

我相信您需要使用join代替,您可以加入以从第二个查询中获取该值

加入文档:https://docs.loganalytics.io/docs/Language-Reference/Tabular-operators/join-operator

连接的左侧是您的"外部"查询,并且联接的右侧将是"内部"查询,虽然不是做1,但你可能做一个更简单的查询,只获取serverEnvId,dbInfo的不同值