blob: 2b133acbbaeb0f897987dd371fec186897b3504f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
<?php
namespace Elastica\Bulk\Action;
use Elastica\Document;
use Elastica\Script;
class UpdateDocument extends IndexDocument
{
/**
* @var string
*/
protected $_opType = self::OP_TYPE_UPDATE;
/**
* 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;
}
/**
* @param \Elastica\Script $script
*
* @return $this
*/
public function setScript(Script $script)
{
parent::setScript($script);
$source = $script->toArray();
if ($script->hasUpsert()) {
$upsert = $script->getUpsert()->getData();
if (!empty($upsert)) {
$source['upsert'] = $upsert;
}
}
$this->setSource($source);
return $this;
}
}
|