How to select Top X queries with GraphQL API

Top X queries are mainly used for performing queries and analysis on data. They help visualize how resources and tools are being used and provide a more detailed analysis of certain conditions that are either more or less commonly used.

To query Top X queries through the GraphQL API, follow the steps described on How to query GraphQL requests on Postman using the https://api.azionapi.net/events/graphql URL.

Then, on Postman’s GraphQL request code box, add the following Top X Query, modifying the tsRange to fit the time interval you want:

query EventsTopUri {
httpEvents(
limit: 5,
filter: {
tsRange: {begin:"2022-11-20T10:10:10", end:"2022-11-27T10:10:10"}
},
aggregate: {count: requestUri}
groupBy: [requestUri]
orderBy: [count_DESC]
)
{
requestUri
count
}
}

The example queries the Events app for raw data with the HTTP dataset. In addition, the count operator requests data aggregation with information from the requestUri field during a set period of time, informed through the tsRange field. The API response was also limited to 5 registers by using the limit field.

Lastly, data were aggregated (groupBy) by the requestUri field and sorted (orderBy) by the return of the count operator in a descending (DESC) order. That way, the largest amount of aggregation responses is shown first.

To query aggregating data, it’s mandatory to inform:

  • A time range interval for queries, using either tsRange or tsGt + tsLt.
  • The fields whose information you want to group, using groupBy.
  • Which consulted data should be exhibited. On the presented example, the requestUri and count fields were used, in which count represents the response of the requestUri aggregation.

Send your request. You’ll receive a response similar to this:

{
"data": {
"httpEvents": [
{
"requestUri": "/requests/images",
"count": 610081
},
{
"requestUri": "/path/to/file/document",
"count": 6270
},
{
"requestUri": "/send/stock",
"count": 3568
}
]
}
}

The GraphQL API returned the Top RequestUri query data according to the query informed in the request.

For more information on aggregating data with the GraphQL API, visit the datasets documentation page.


Contributors