【问题标题】:Page results from Azure Application Insights Analytics APIAzure Application Insights Analytics API 的页面结果
【发布时间】:2017-04-12 13:37:23
【问题描述】:

是否可以“分页”分析 API 的结果?

如果我使用以下查询(通过 http POST)

{
 "query":"customEvents | project customDimensions.FilePath, timestamp 
         | where timestamp > now(-100d) | order by timestamp desc | limit 25"
}

我可以在一个结果集中获得多达 10,000 个结果。有什么方法可以使用类似于他们为事件 API 提供的 $skip 的东西吗?像“SKIP 75 TAKE 25”之类的东西来获得第 4 页的结果。

【问题讨论】:

    标签: c# azure azure-application-insights ms-app-analytics


    【解决方案1】:

    [编辑:这个答案现在已经过时了,查询语言中添加了一个row_number 函数。如果有人遇到类似于此答案的奇怪查询,则此答案留作历史用途]

    不容易

    如果您可以使用 /events ODATA 查询路径而不是 /query 路径,则支持分页。但不像您那样真正的自定义查询。

    要获得类似分页的功能,您需要进行复杂的查询,并使用summarizemakeList 并在查询中创建rowNum 字段,然后使用mvexpand 重新展开列表,然后按rowNum 过滤。它非常复杂且不直观,例如:

    customEvents 
    | project customDimensions.FilePath, timestamp 
    | where timestamp > now(-100d) 
    | order by timestamp desc 
    // squishes things down to 1 row where each column is huge list of values
    | summarize filePath=makelist(customDimensions.FilePath, 1000000)
        , timestamp=makelist(timestamp, 1000000)
        // make up a row number, not sure this part is correct
        , rowNum = range(1,count(strcat(filePath,timestamp)),1)
    // expands the single rows into real rows
    | mvexpand filePath,timestamp,rowNum limit 1000000
    | where rowNum > 0 and rowNum <= 100 // you'd change these values to page
    

    我相信 appinsights 用户语音上已经有一个请求,以支持查询语言中的分页运算符。

    这里的另一个假设是 在您工作时基础表中的数据不会改变。如果新数据出现在您的通话之间,例如

    1. 给我第 0-99 行
    2. 出现 50 个新行
    3. 给我第 100-199 行

    那么第 3 步实际上会返回 50 个重复的行,这些行是在第 1 步中获得的。

    【讨论】:

      【解决方案2】:

      现在有一种更正确的方法可以做到这一点,使用自我之前的回答以来添加到查询语言中的新运算符。

      这两个运算符是serializerow_number()

      serialize 确保数据的形状和顺序适用于row_number()。一些现有的运算符,如order by,已经创建了序列化数据。

      还有prev()next() 运算符可以从序列化结果中的前一行或后一行获取值。

      【讨论】:

      • 我对实现分页有同样的要求。我的示例查询如下,请您告诉我 Ican 如何实现分页。定制活动 |项目 TimeGenerated,ResourceId,OperationName,OperationVersion,Resource,ResourceGroup,ResourceProvider,SubscriptionId
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-29
      • 2018-10-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多