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
Useinclude 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.
using (var session = store.OpenSession())
{
var baseTime = DateTime.Today;
var from = baseTime;
var to = baseTime.AddMinutes(5);
// Define the Raw Query:
IRawDocumentQuery<User> query = session.Advanced.RawQuery<User>
// Use 'include timeseries' in the RQL
("from Users include timeseries('HeartRates', $from, $to)")
// Pass optional parameters
.AddParameter("from", from)
.AddParameter("to", to);
// Execute the query:
// For each document in the query results,
// the time series entries will be 'loaded' to the session along with the document
var users = query.ToList();
// The following call to 'Get' will Not trigger a server request,
// the entries will be retrieved from the session's cache.
IEnumerable<TimeSeriesEntry> entries = session.TimeSeriesFor(users[0], "HeartRates")
.Get(from, to);
}
The entries we Get after the query, are retrieved from the session's cache.