Skip to main content

Get Query Statistics

  • Detailed query statistics can be retrieved for every executed query using the Statistics method.

  • Stats such as query duration, number of results, index name used in the query, and more,
    are returned in the QueryStatistics object.

  • In This Page:

Get query statistics

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();

int numberOfResults = stats.TotalResults; // Get results count
long queryDuration = stats.DurationInMs; // Get query duration
string indexNameUsed = stats.IndexName; // Get index name used in query
// ...

Syntax

IRavenQueryable<T> Statistics(out QueryStatistics stats);
ParameterTypeDescription
statsQueryStatisticsAn 'out' param for getting the query statistics

public class QueryStatistics
{
public bool IsStale { get; set; }
public long DurationInMs { get; set; }
public long TotalResults { get; set; }
public long SkippedResults { get; set; }
public long? ScannedResults { get; set; }
public DateTime Timestamp { get; set; }
public string IndexName { get; set; }
public DateTime IndexTimestamp { get; set; }
public DateTime LastQueryTime { get; set; }
public long? ResultEtag { get; set; }
public string NodeTag { get; set; }
}
PropertyTypeDescription
IsStaleboolAre the results returned by the query potentially stale
DurationInMslongQuery duration on the server side in Milliseconds
TotalResultsintThe total count of results that matched the query as Int32.
Matching query results can also be counted as Int32 using Count.
LongTotalResultslongThe total count of the results that matched the query as Int64.
Matching query results can also be counted as Int64 using LongCount.
SkippedResultsintThe number of results skipped by the server.
Learn more in paging through tampered results.
TimestampDateTimeThe time when the query results were unstale
IndexNamestringThe name of the queried index
IndexTimestampIndexTimestampThe timestamp of the queried index
LastQueryTimeDateTimeThe timestamp of the last time the index was queried
ResultEtaglong?Results Etag
NodeTagstringTag of the cluster node that responded to the query