Get Query Statistics
-
Detailed query statistics can be retrieved for every executed query using the
Statisticsmethod. -
Stats such as query duration, number of results, index name used in the query, and more,
are returned in theQueryStatisticsobject. -
In This Page:
Get query statistics
- Query
- Query_async
- DocumentQuery
- RQL
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
// ...
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
// ...
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();
long 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 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; }
}
| 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 | long | The total count of results that matched the query as Int32.Matching query results can also be counted as Int32 using Count. |
| SkippedResults | long | The number of results skipped by the server. Learn more in paging through tampered results. |
| ScannedResults | long? | The number of results scanned by the query. Relevant only when using a filter clause in the query. |
| 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 |