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

$stats = new QueryStatistics();

$employees = $session->query(Employee::class)
    ->whereEquals("FirstName", "Robert")
    ->statistics($stats)
    ->toList();

$totalResults = $stats->getTotalResults();
$durationInMs = $stats->getDurationInMs();
from "Employees" where FirstName == "Robert"

Syntax

public function statistics(QueryStatistics &$stats): DocumentQueryInterface;
Parameter Type Description
$stats QueryStatistics An 'out' param for getting the query statistics


class QueryStatistics
{
    private bool $isStale = false;
    private int $durationInMs = 0;
    private int $totalResults = 0;
    private int $longTotalResults = 0;
    private int $skippedResults = 0;
    private ?int $scannedResults = null;
    private ?DateTimeInterface $timestamp = null;
    private ?string $indexName = null;
    private ?DateTimeInterface $indexTimestamp = null;
    private ?DateTimeInterface $lastQueryTime = null;
    private ?int $resultEtag = null;
    private ?string $nodeTag = null;
}
Property Type Description
$isStale bool Are the results returned by the query potentially stale
$durationInMs int Query duration on the server side in Milliseconds
$totalResults,
$longTotalResults
int The total count of results that matched the query.
Matching query results can also be counted using Count.
$skippedResults int The number of results skipped by the server.
Learn more in paging through tampered results.
$timestamp ?DateTimeInterface The time when the query results were unstale
$indexName ?string The name of the queried index
$indexTimestamp ?DateTimeInterface The timestamp of the queried index
$lastQueryTime ?DateTimeInterface The timestamp of the last time the index was queried
$resultEtag ?int Results Etag
$nodeTag ?string Tag of the cluster node that responded to the query