Page results from Azure Application Insights Analytics API

核能气质少年 提交于 2019-12-11 07:29:42

问题


Is it possible to "page" the results from the Analytics API?

If I use the following Query (via http POST)

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

I get up to 10,000 results back in one result set. Is there any way to use something similar to the $skip that they have for the events API? Like "SKIP 75 TAKE 25" or something to get the 4th page of results.


回答1:


[edit: this answer is now out of date, there has been a row_number function added to the query language. this answer left for historical purposes if anyone runs into strange queries that look like this answer]

Not easily.

If you can use the /events ODATA query path instead of the /query path, that supports paging. but not really custom queries like you have.

To get something like paging, you need to make a complicated query, and use summarize and makeList and invent a rowNum field in your query, then use mvexpand to re-expand the lists and then filter by the rowNum. it's pretty complicated and unintuitive, something like:

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

i believe there's already a request on the appinsights uservoice to support paging operators in the query language.

the other assumption here is that data isn't changing in the underlying table while you're doing work. if new data appears between your calls, like

  1. give me rows 0-99
  2. 50 new rows appear
  3. give me rows 100-199

then step 3 is actually giving you back 50 duplicate rows that you just got in step 1.




回答2:


There's a more correct way to do this now, using new operators that were added to the query language since my previous answer.

The two operators are serialize and row_number().

serialize ensures the data is in a shape and order that works with row_number(). Some of the existing operators like order by already create serialized data.

there's also prev() and next() operators that can get the values from previous or next rows in a serialized result.



来源:https://stackoverflow.com/questions/43371188/page-results-from-azure-application-insights-analytics-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!