/** * Set the document for this bulk update action. * * @param \Elastica\Document $document * * @return $this */ public function setDocument(Document $document) { parent::setDocument($document); $source = array('doc' => $document->getData()); if ($document->getDocAsUpsert()) { $source['doc_as_upsert'] = true; } elseif ($document->hasUpsert()) { $upsert = $document->getUpsert()->getData(); if (!empty($upsert)) { $source['upsert'] = $upsert; } } $this->setSource($source); return $this; }
/** * Set the document for this bulk update action. * If the given Document object has a script, the script will be used in the update operation. * @param \Elastica\Document $document * @return \Elastica\Bulk\Action\IndexDocument */ public function setDocument(Document $document) { parent::setDocument($document); if ($document->hasScript()) { $source = $document->getScript()->toArray(); $documentData = $document->getData(); if (!empty($documentData)) { $source['upsert'] = $documentData; } $this->setSource($source); } else { $this->setSource(array('doc' => $document->getData())); } return $this; }