Session: Include Time Series With Raw Queries


You can include time series data while running a raw RQL query via session.Advanced.RawQuery.


Include Time Series Data with Advanced.RawQuery

To include time series data while querying via Advanced.RawQuery, use the include timeseries expression in your RQL query.

Syntax

  • Advanced.RawQuery

    • Definition

      IRawDocumentQuery<T> RawQuery<T>(string query);
    • Parameters

      Parameters Type Description
      query string Raw RQL Query

Usage Flow

  • Open a session
  • Call session.Advanced.RawQuery
    Use include timeseries in your query
  • Pass include timeseries its arguments:
    • Time series name
    • Range start
    • Range end

Usage Sample

In this sample, we use a raw query to retrieve a document and include entries from the document's "Heartrate" time series.

// Include a Time Series in a Raw Query
using (var session = store.OpenSession())
{
    var baseline = DateTime.Today;

    var start = baseline;
    var end = baseline.AddHours(1);

    IRawDocumentQuery<User> query = session.Advanced.RawQuery<User>
              ("from Users include timeseries('HeartRates', $start, $end)")
        .AddParameter("start", start)
        .AddParameter("end", end);

    var result = query.ToList();

    IEnumerable<TimeSeriesEntry> val = session.TimeSeriesFor(result[0], "HeartRates")
        .Get(start, end);
}

The entries we Get after the query, are retrieved from the session's cache.