yii\elasticsearch\Command::insert PHP Method

insert() public method

Inserts a document into an index
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html
public insert ( string $index, string $type, string | array $data, null $id = null, array $options = [] ) : mixed
$index string
$type string
$data string | array json string or array of data to store
$id null the documents id. If not specified Id will be automatically chosen
$options array
return mixed
    public function insert($index, $type, $data, $id = null, $options = [])
    {
        if (empty($data)) {
            $body = '{}';
        } else {
            $body = is_array($data) ? Json::encode($data) : $data;
        }
        if ($id !== null) {
            return $this->db->put([$index, $type, $id], $options, $body);
        } else {
            return $this->db->post([$index, $type], $options, $body);
        }
    }