Upsert-type functionality for existing ORM Entities
This is an attempt to fix the issue: https://github.com/FriendsOfSymfony/FOSElasticaBundle/issues/526 It will cause a significant slowdown in a large batch, but it appears to be the only way to prevent an exception from bubbling up during a normal use case.
This commit is contained in:
parent
40e79b2abe
commit
20810fa415
|
@ -107,7 +107,15 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
{
|
||||
$documents = array();
|
||||
foreach ($objects as $object) {
|
||||
$documents[] = $this->transformToElasticaDocument($object);
|
||||
$document = $this->transformToElasticaDocument($object);
|
||||
|
||||
try {
|
||||
$this->type->getDocument($document->getId());
|
||||
} catch (NotFoundException $e) {
|
||||
$this->type->addDocument($document);
|
||||
}
|
||||
|
||||
$documents[] = $document;
|
||||
}
|
||||
$this->type->updateDocuments($documents);
|
||||
}
|
||||
|
@ -136,4 +144,4 @@ class ObjectPersister implements ObjectPersisterInterface
|
|||
{
|
||||
return $this->transformer->transform($object, $this->fields);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue