来自 Azure Application Insights Analytics 的页面结果 API

Page results from Azure Application Insights Analytics API

是否可以 "page" 来自 Analytics 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 页的结果。

[编辑:这个答案现在已经过时了,查询语言中添加了一个 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 uservoice 上已经有人请求支持查询语言中的分页运算符。

此处的另一个假设是,在您工作时,基础 table 中的数据不会发生变化。如果新数据出现 在您的通话之间,例如

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

然后第 3 步 实际上 返回您在第 1 步中刚刚获得的 50 个重复行。

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

两个运算符是serializerow_number()

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

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