首页 > 解决方案 > 按每个事件组的时间戳显示第一个条目

问题描述

我们为用户发送到聊天机器人的每条消息收集应用程序洞察中的自定义事件。该事件称为user_message。我们使用自定义维度字段customDimensions.conversationid来了解哪个消息与哪个对话相关。

我想查看每个对话的第一条消息,所以基本上是基于对话 ID 的每个事件的“最旧”时间戳。

我尝试使用 arg_max 但我不知道它是如何工作的。

customEvents
| extend itemType = iif(itemType == 'customEvent',itemType,"")
| where (itemType == 'customEvent')
| where name == 'User_Message'

我能够按对话ID显示所有用户消息,但是它显示了多行,我只需要按对话的第一条消息。

数据模型:

timestamp [UTC] 2019-04-05T13:24:10.359Z
name User_Message
itemType customEvent
    customDimensions
    confidence N/A 
    conversationId BNu0SqC5RfA1S0lZmdxxxxx
    intent N/A
    userMessage user text
operation_Name POST /api/messages
operation_Id xxxxxxxa5d422eadebfebb2
operation_ParentId xxxxx545a5d422eadebfebb2.99811380_13.f033f887_
application_Version 1.0.0
client_Type PC
client_OS Windows_NT 10.0.14393
client_IP 0.0.0.0
client_City Amsterdam
client_StateOrProvince North Holland
client_CountryOrRegion Netherlands
cloud_RoleName Web
cloud_RoleInstance XXXXXXXFF74D594
appId ccccccc-8b24-41bb-a02a-1cb101da84e5
appName bot-XXXXX
iKey XXXXXX
sdkVersion node:XX
itemId XXXXXXXX-57a6-11e9-a5a7-ebc91e7cf64e
itemCount 1

解决方案

customEvents
| extend itemType = iif(itemType == 'customEvent',itemType,"")
| where (itemType == 'customEvent')
| where (name=='User_Message')
| summarize list=makeset(customDimensions.userMessage) by 
tostring(customDimensions.conversationId)
| mv-expand firstMessage=list[0]

标签: azureazure-application-insights

解决方案


更新:

customEvents 
| where name == "User_Message"
| summarize timestamp=min(timestamp) by myconid=tostring(customDimensions.[conversationID])
| join kind= inner (
   customEvents
   | where name == "User_Message"
   | extend myconid = tostring(customDimensions.[conversationID])
) on myconid,timestamp

您可以使用内部连接来做到这一点。

我没有您的数据,因此在您的情况下,代码如下所示(也许您需要进行一些更改):

customEvents
| summarize timestamp=min(timestamp) by conversationID 
| join kind= inner (
   customEvents
) on conversationID,timestamp
| project-away conversationID1,timestamp1

如果您有更多问题,请告诉我。


推荐阅读