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 theQueryStatistics
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
// ...
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();
int numberOfResults = stats.TotalResults; // Get results count
long queryDuration = stats.DurationInMs; // Get query duration
string indexNameUsed = stats.IndexName; // Get index name used in query
// ...
List<Employee> employees = session.Advanced
.DocumentQuery<Employee>()
.WhereEquals(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
// ...
from "Employees" where FirstName == "Anne"
Syntax
IRavenQueryable<T> Statistics(out QueryStatistics stats);
Parameter | Type | Description |
---|---|---|
stats | QueryStatistics |
An 'out' param for getting the query statistics |
public class QueryStatistics
{
public bool IsStale { get; set; }
public long DurationInMs { get; set; }
public int TotalResults { get; set; }
public long LongTotalResults { get; set; }
public int SkippedResults { 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; }
}
Property | Type | Description |
---|---|---|
IsStale | bool |
Are the results returned by the query potentially stale |
DurationInMs | long |
Query duration on the server side in Milliseconds |
TotalResults | int |
The total count of results that matched the query as Int32 .Matching query results can also be counted as Int32 using Count. |
LongTotalResults | long |
The total count of the results that matched the query as Int64 .Matching query results can also be counted as Int64 using LongCount. |
SkippedResults | int |
The number of results skipped by the server. Learn more in paging through tampered results. |
Timestamp | DateTime |
The time when the query results were unstale |
IndexName | string |
The name of the queried index |
IndexTimestamp | IndexTimestamp |
The timestamp of the queried index |
LastQueryTime | DateTime |
The timestamp of the last time the index was queried |
ResultEtag | long? |
Results Etag |
NodeTag | string |
Tag of the cluster node that responded to the query |