按每个事件组的时间戳显示第一个条目

问题描述 投票:0回答:1

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

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

我尝试使用arg_max,但我没弄清楚它是如何工作的。

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

我能够通过conversationID显示所有用户消息ordert然而它显示了多行,我只需要通过对话的第一条消息。

数据模型:

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]
azure azure-application-insights
1个回答
0
投票

更新:

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

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

© www.soinside.com 2019 - 2024. All rights reserved.