Retrieve Events from a Persisted Aggregation

Reading events stored in a persisted aggregation from a specific view using the readPersistedAggregation() function

Query

logscale
readPersistedAggregation("myTag", view="myView")

Introduction

The readPersistedAggregation() function can be used to retrieve pre-aggregated events that have been stored using a persisted aggregation. Persisted aggregations allow query results to be saved and reused across multiple queries, reducing the need to recompute expensive aggregations repeatedly. A persisted aggregation is referenced using a combination of tag and view. The function thus takes as input a tag and an optional view parameter and returns as output only the events associated with referenced persisted aggregation.

In this example, the readPersistedAggregation() function is used to retrieve all events stored under the tag myTag in the view myView. Only events matching the specified tag are returned; events from other tags in the same view are excluded.

In this scenario, a persisted aggregation has been set up to periodically aggregate web server access log data โ€” counting requests per HTTP status code and endpoint โ€” and store the results under the tag myTag in the view myView. The readPersistedAggregation() function is then used to read back those stored results for further analysis or visualization without re-running the original aggregation query.

Example incoming data might look like this:

@timestampstatus_codeendpointrequest_countavg_response_mserror_rate
2026-03-15T08:00:00Z200/api/users15231420.00
2026-03-15T08:00:00Z200/api/products987980.00
2026-03-15T08:00:00Z200/api/orders6542100.00
2026-03-15T08:00:00Z301/api/legacy45120.00
2026-03-15T08:00:00Z400/api/users78551.00
2026-03-15T08:00:00Z400/api/products34481.00
2026-03-15T08:00:00Z401/api/orders112331.00
2026-03-15T08:00:00Z403/api/admin29281.00
2026-03-15T08:00:00Z404/api/users56221.00
2026-03-15T08:00:00Z404/api/products41191.00
2026-03-15T08:00:00Z500/api/orders188901.00
2026-03-15T08:00:00Z500/api/users712401.00
2026-03-15T08:00:00Z503/api/products321001.00
2026-03-15T09:00:00Z200/api/users17891380.00
2026-03-15T09:00:00Z200/api/products1102950.00
2026-03-15T09:00:00Z200/api/orders7232050.00
2026-03-15T09:00:00Z301/api/legacy38110.00
2026-03-15T09:00:00Z400/api/users91521.00
2026-03-15T09:00:00Z401/api/orders98311.00
2026-03-15T09:00:00Z404/api/products63201.00
2026-03-15T09:00:00Z500/api/orders229101.00
2026-03-15T09:00:00Z503/api/users519801.00

Step-by-Step

  1. Starting with the source repository events.

  2. logscale
    readPersistedAggregation("myTag", view="myView")

    The readPersistedAggregation() function retrieves all events previously stored in the persisted aggregation identified by the tag myTag. The view parameter specifies that the aggregation is read from the view named myView. If the view parameter is omitted, the function defaults to reading from the current view in which the query is executed. Only events associated with the tag myTag are returned; any other persisted aggregations stored under different tags within myView are excluded from the result set. The function acts as a source in the query pipeline, meaning it replaces the normal event stream with the stored aggregation results, making it suitable as the first and only statement when the goal is simply to retrieve the persisted data.

  3. Event Result set.

Summary and Results

The query is used to read back pre-aggregated web server access log data that was previously stored under the tag myTag in the view myView, returning all fields and events captured at the time the persisted aggregation was last written.

This query is useful, for example, to power dashboards or alerts that need to display aggregated HTTP traffic metrics โ€” such as request counts, average response times, and error rates per endpoint and status code โ€” without incurring the cost of re-running the full aggregation query over raw log data each time.

Sample output from the incoming example data:

@timestampstatus_codeendpointrequest_countavg_response_mserror_rate
2026-03-15T08:00:00Z200/api/users15231420.00
2026-03-15T08:00:00Z200/api/products987980.00
2026-03-15T08:00:00Z200/api/orders6542100.00
2026-03-15T08:00:00Z301/api/legacy45120.00
2026-03-15T08:00:00Z400/api/users78551.00
2026-03-15T08:00:00Z400/api/products34481.00
2026-03-15T08:00:00Z401/api/orders112331.00
2026-03-15T08:00:00Z403/api/admin29281.00
2026-03-15T08:00:00Z404/api/users56221.00
2026-03-15T08:00:00Z404/api/products41191.00
2026-03-15T08:00:00Z500/api/orders188901.00
2026-03-15T08:00:00Z500/api/users712401.00
2026-03-15T08:00:00Z503/api/products321001.00
2026-03-15T09:00:00Z200/api/users17891380.00
2026-03-15T09:00:00Z200/api/products1102950.00
2026-03-15T09:00:00Z200/api/orders7232050.00
2026-03-15T09:00:00Z301/api/legacy38110.00
2026-03-15T09:00:00Z400/api/users91521.00
2026-03-15T09:00:00Z401/api/orders98311.00
2026-03-15T09:00:00Z404/api/products63201.00
2026-03-15T09:00:00Z500/api/orders229101.00
2026-03-15T09:00:00Z503/api/users519801.00

Note that the output is a direct reflection of the data stored in the persisted aggregation at the time it was last written โ€” no additional filtering, transformation, or re-aggregation is applied by the readPersistedAggregation() function itself.

Note also that events from other tags that may exist within myView are entirely absent from the results, confirming that the tag filter is applied strictly. Note that the error_rate field carries a value of 1.00 for all non-2xx and non-3xx status codes, reflecting that these were pre-computed and stored as part of the original aggregation logic, and their meaning depends entirely on how the persisted aggregation was defined.