Get Query Statistics
Query statistics can provide important information about a query like duration, total number of results, staleness information, etc. To access statistics use the Statistics
method.
Syntax
List<Employee> employees = session
.Query<Employee>()
.Where(x => x.FirstName == "Anne")
// Get query stats:
// * Call 'Statistics'
// * Pass an out 'QueryStatistics' param for getting the stats
.Statistics(out QueryStatistics stats)
.ToList();
long numberOfResults = stats.TotalResults; // Get results count
long queryDuration = stats.DurationInMs; // Get query duration
string indexNameUsed = stats.IndexName; // Get index name used in query
// ...
Parameters | ||
---|---|---|
stats | QueryStatistics | Statistics for query. |
Example
List<Employee> employees = await asyncSession
.Query<Employee>()
.Where(x => x.FirstName == "Anne")
// Get query stats:
// * Call 'Statistics'
// * Pass an out 'QueryStatistics' param for getting the stats
.Statistics(out QueryStatistics stats)
.ToListAsync();
long numberOfResults = stats.TotalResults; // Get results count
long queryDuration = stats.DurationInMs; // Get query duration
string indexNameUsed = stats.IndexName; // Get index name used in query
// ...