Elastica\Bulk::addRawData PHP 메소드

addRawData() 공개 메소드

public addRawData ( array $data )
$data array
    public function addRawData(array $data)
    {
        foreach ($data as $row) {
            if (is_array($row)) {
                $opType = key($row);
                $metadata = reset($row);
                if (Action::isValidOpType($opType)) {
                    // add previous action
                    if (isset($action)) {
                        $this->addAction($action);
                    }
                    $action = new Action($opType, $metadata);
                } elseif (isset($action)) {
                    $action->setSource($row);
                    $this->addAction($action);
                    $action = null;
                } else {
                    throw new InvalidException('Invalid bulk data, source must follow action metadata');
                }
            } else {
                throw new InvalidException('Invalid bulk data, should be array of array, Document or Bulk/Action');
            }
        }
        // add last action if available
        if (isset($action)) {
            $this->addAction($action);
        }
        return $this;
    }

Usage Example

예제 #1
0
 /**
  * Bulk operation
  *
  * Every entry in the params array has to exactly on array
  * of the bulk operation. An example param array would be:
  *
  * array(
  *         array('index' => array('_index' => 'test', '_type' => 'user', '_id' => '1')),
  *         array('user' => array('name' => 'hans')),
  *         array('delete' => array('_index' => 'test', '_type' => 'user', '_id' => '2'))
  * );
  *
  * @throws \Elastica\Exception\ResponseException
  * @throws \Elastica\Exception\InvalidException
  * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
  *
  * @param  array                      $params Parameter array
  * @return \Elastica\Bulk\ResponseSet Response object
  */
 public function bulk(array $params)
 {
     if (empty($params)) {
         throw new InvalidException('Array has to consist of at least one param');
     }
     $bulk = new Bulk($this);
     $bulk->addRawData($params);
     return $bulk->send();
 }
All Usage Examples Of Elastica\Bulk::addRawData