yii\elasticsearch\Connection::post PHP Method

post() public method

Performs POST HTTP request
public post ( string | array $url, array $options = [], string $body = null, boolean $raw = false ) : mixed
$url string | array URL
$options array URL options
$body string request body
$raw boolean if response body contains JSON and should be decoded
return mixed response
    public function post($url, $options = [], $body = null, $raw = false)
    {
        $this->open();
        return $this->httpRequest('POST', $this->createUrl($url, $options), $body, $raw);
    }

Usage Example

 /**
  * Executes the bulk command.
  * @return mixed
  * @throws yii\base\InvalidCallException
  */
 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);
 }
All Usage Examples Of yii\elasticsearch\Connection::post