Elastica\Bulk::addDocument PHP Method

addDocument() public method

public addDocument ( Document $document, string $opType = null )
$document Document
$opType string
    public function addDocument(Document $document, $opType = null)
    {
        $action = AbstractDocumentAction::create($document, $opType);
        return $this->addAction($action);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @group functional
  */
 public function testRetry()
 {
     $index = $this->_createIndex();
     $type = $index->getType('bulk_test');
     $client = $index->getClient();
     $doc1 = $type->createDocument(1, array('name' => 'Mister Fantastic'));
     $doc1->setOpType(Action::OP_TYPE_UPDATE);
     $doc1->setRetryOnConflict(5);
     $bulk = new Bulk($client);
     $bulk->addDocument($doc1);
     $actions = $bulk->getActions();
     $metadata = $actions[0]->getMetadata();
     $this->assertEquals(5, $metadata['_retry_on_conflict']);
     $script = new \Elastica\Script('');
     $script->setRetryOnConflict(5);
     $bulk = new Bulk($client);
     $bulk->addScript($script);
     $actions = $bulk->getActions();
     $metadata = $actions[0]->getMetadata();
     $this->assertEquals(5, $metadata['_retry_on_conflict']);
 }