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

// Define an output param for getting the query stats
let stats;

const employees = await session
    .query({ collection: "Employees" })
    .whereEquals("FirstName", "Anne")
     // Get query stats:
     // * Call 'statistics', pass a callback function
     // * Output param 'stats' will be filled with the stats when query returns 
    .statistics(s => stats = s)
    .all();

const numberOfResults = stats.value.totalResults; // Get results count
const queryDuration = stats.value.durationInMs;   // Get query duration
const indexNameUsed = stats.value.indexName;      // Get index name used in query
// ...
from "Employees" where FirstName == "Anne"

Syntax

query.statistics(statsCallback);
Parameter Type Description
statsCallback (stats) => void
  • A callback function with an output parameter.
  • The parameter passed to the callback will be filled with the QueryStatistics object when query returns.
QueryStatistics
isStale boolean Are the results returned by the query potentially stale
durationInMs number Query duration on the server side in Milliseconds
totalResults number The total count of results that matched the query
longTotalResults number The total count of results that matched the query (same as totalResults)
skippedResults number The number of results skipped by the server.
Learn more in paging through tampered results.
timestamp Date The time when the query results were unstale
indexName string The name of the queried index
indexTimestamp Date The timestamp of the queried index
lastQueryTime Date The timestamp of the last time the index was queried
resultEtag number Results Etag
nodeTag string Tag of the cluster node that responded to the query