yii\elasticsearch\Query::count PHP Method

count() public method

Returns the number of records.
public count ( string $q = '*', Connection $db = null ) : integer
$q string the COUNT expression. This parameter is ignored by this implementation.
$db Connection the database connection used to execute the query. If this parameter is not given, the `elasticsearch` application component will be used.
return integer number of records
    public function count($q = '*', $db = null)
    {
        // TODO consider sending to _count api instead of _search for performance
        // only when no facety are registerted.
        // http://www.elastic.co/guide/en/elasticsearch/reference/current/search-count.html
        // http://www.elastic.co/guide/en/elasticsearch/reference/1.x/_search_requests.html
        $options = [];
        $options['search_type'] = 'count';
        return $this->createCommand($db)->search($options)['hits']['total'];
    }