Query.php
public function scalar($field, $db = null)
    {
        if ($this->emulateExecution) {
            return null;
        }
        $record = self::one($db);
        if ($record !== false) {
            if ($field === '_id') {
                return $record['_id'];
            } elseif (isset($record['_source'][$field])) {
                return $record['_source'][$field];
            } elseif (isset($record['fields'][$field])) {
                return count($record['fields'][$field]) == 1 ? reset($record['fields'][$field]) : $record['fields'][$field];
            }
        }
        return null;
    }
public function scalar($field, $db = null)
    {
        if ($this->emulateExecution) {
            return null;
        }
        $record = self::one($db);
        if ($record !== false) {
            if ($field === '_id') {
                return $record['_id'];
            } elseif (isset($record['_source'][$field])) {
                return $record['_source'][$field];
            } elseif (isset($record['fields'][$field])) {
                return count($record['fields'][$field]) == 1 ? reset($record['fields'][$field]) : $record['fields'][$field];
            }
        }
        return null;
    }
public function scalar ( $ field , $ db = null ) { if ( $ this -> emulateExecution ) { return null ; } $ record = self :: one ( $ db ) ; if ( $ record !== false ) { if ( $ field === '_id' ) { return $ record [ '_id' ] ; } elseif ( isset ( $ record [ '_source' ] [ $ field ] ) ) { return $ record [ '_source' ] [ $ field ] ; } elseif ( isset ( $ record [ 'fields' ] [ $ field ] ) ) { return count ( $ record [ 'fields' ] [ $ field ] ) == 1 ? reset ( $ record [ 'fields' ] [ $ field ] ) : $ record [ 'fields' ] [ $ field ] ; } } return null ; }
Returns the query result as a scalar value.
The value returned will be the specified field in the first document of the query results.
@param string $field name of the attribute to select
@param Connection $db the database connection used to execute the query.
If this parameter is not given, the `elasticsearch` application component will be used.
@return string the value of the specified attribute in the first record of the query result.
Null is returned if the query result is empty or the field does not exist.
Returns the query result as a scalar value . The value returned will be the specified field in the first document of the query results .