带有WHERE子句的Azure Log Analytics查询不会产生任何结果

时间:2019-02-21 09:45:40

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

我正在使用Azure Log Analytics在源自AppCenter Diagnostics的Azure Application Insights中查询日志条目。 在某些日志条目中,我使用自定义属性。 现在,我试图编写一个查询以仅显示具有给定值的某些属性的值。

我的原始查询如下所示,并产生预期的结果:

customEvents
| where (timestamp >= datetime(2019-02-20T09:04:00.000Z) and timestamp <= datetime(2019-02-21T09:04:00.000Z)) 
| top 101 by timestamp desc
| project timestamp, name, customDimensions.Properties
| where name == "Navigated to details view"

Query result

将鼠标悬停在“ productId”属性上会显示一个加号,该加号允许添加过滤条件:

Filter for property

选择此选项扩展了我的查询范围:

customEvents
| where (timestamp >= datetime(2019-02-20T09:04:00.000Z) and timestamp <= datetime(2019-02-21T09:04:00.000Z)) 
| top 101 by timestamp desc
| project timestamp, name, customDimensions.Properties
| where name == "Navigated to details view"
| where customDimensions_Properties.productId == 4711 

到目前为止,太好了。如果现在尝试运行此查询,则会收到消息“找不到结果”:

No results found

编辑: 我还尝试将底部的where子句添加到第一个where子句

customEvents
| where (timestamp >= datetime(2019-02-20T09:04:00.000Z) and timestamp <= datetime(2019-02-21T09:04:00.000Z)) 
and name == "Navigated to details view" 
and customDimensions.Properties.productId == 4711
| top 101 by timestamp desc
| project timestamp, name, customDimensions

不幸的是也没有结果。

编辑2: 我还尝试了此查询,以查看是否可以在查询中投影productId属性而不将其包含在where子句中:

customEvents
| where (timestamp >= datetime(2019-02-20T09:04:00.000Z) and timestamp <= datetime(2019-02-21T09:04:00.000Z)) 
and name == "Navigated to details view" 
| top 101 by timestamp desc
| project timestamp, name, customDimensions, customDimensions.Properties.productId

但是此列为空: Project productId

我有什么想念的吗?工具是否存在问题并产生错误的查询?

谢谢您的帮助!

1 个答案:

答案 0 :(得分:1)

您将必须使用mvexpand等各种运算符并进行扩展才能满足您的要求。请在下面的示例查询中找到。请注意,下面的示例只是一个示例查询,您可能需要进行一些调整才能使其按预期工作并获得预期的输出(例如,如果您期望在特定时间戳记下具有特定事件的customEvent的所有列进行输出, productId等)

customEvents
| where (timestamp >= datetime(2019-02-20T09:04:00.000Z) and timestamp <= datetime(2019-02-21T09:04:00.000Z)) 
| top 101 by timestamp desc
| project timestamp, name, customDimensions_Properties
| where name == "Navigated to details view"
| extend CDP_toString=parsejson(tostring(customDimensions_Properties))
| mvexpand CDP_toString
| project CDP_toString
| where CDP_toString.['productId'] == "4711";

希望这会有所帮助!!干杯!! :)