yii\elasticsearch\ActiveRecord::primaryKeysByCondition PHP Method

primaryKeysByCondition() protected static method

Performs a quick and highly efficient scroll/scan query to get the list of primary keys that satisfy the given condition. If condition is a list of primary keys (e.g.: ['_id' => ['1', '2', '3']]), the query is not performed for performance considerations.
See also: updateAll()
See also: updateAllCounters()
See also: deleteAll()
Since: 2.0.4
protected static primaryKeysByCondition ( array $condition ) : array
$condition array please refer to [[ActiveQuery::where()]] on how to specify this parameter
return array primary keys that correspond to given conditions
    protected static function primaryKeysByCondition($condition)
    {
        $pkName = static::primaryKey()[0];
        if (count($condition) == 1 && isset($condition[$pkName])) {
            $primaryKeys = (array) $condition[$pkName];
        } else {
            //fetch only document metadata (no fields), 1000 documents per shard
            $query = static::find()->where($condition)->asArray()->source(false)->limit(1000);
            $primaryKeys = [];
            foreach ($query->each('1m') as $document) {
                $primaryKeys[] = $document['_id'];
            }
        }
        return $primaryKeys;
    }