yii\elasticsearch\BulkCommand::execute PHP Method

execute() public method

Executes the bulk command.
public execute ( ) : mixed
return mixed
    public function execute()
    {
        //valid endpoints are /_bulk, /{index}/_bulk, and {index}/{type}/_bulk
        if ($this->index === null && $this->type === null) {
            $endpoint = ['_bulk'];
        } elseif ($this->index !== null && $this->type === null) {
            $endpoint = [$this->index, '_bulk'];
        } elseif ($this->index !== null && $this->type !== null) {
            $endpoint = [$this->index, $this->type, '_bulk'];
        } else {
            throw new InvalidCallException('Invalid endpoint: if type is defined, index must be defined too.');
        }
        if (empty($this->actions)) {
            $body = '{}';
        } elseif (is_array($this->actions)) {
            $body = '';
            foreach ($this->actions as $action) {
                $body .= Json::encode($action) . "\n";
            }
        } else {
            $body = $this->actions;
        }
        return $this->db->post($endpoint, $this->options, $body);
    }