我目前在我的项目中使用 FOSElasticaBundle 并且要搜索的实体正在使用softdeletable。这似乎不太顺利,因为当实体被软删除时,弹性搜索上的索引没有被删除。再次填充索引是一项非常昂贵的操作,由于我拥有的大型项目集(150 万个项目),需要 30 分钟才能完成。
手动从弹性搜索中删除索引的最佳方法是什么?我打算使用 softdeletable 侦听器,因此当发生 softdelete 时,我会手动将其从索引中删除。但我不确定如何通过 elastica 做到这一点。
我目前在我的项目中使用 FOSElasticaBundle 并且要搜索的实体正在使用softdeletable。这似乎不太顺利,因为当实体被软删除时,弹性搜索上的索引没有被删除。再次填充索引是一项非常昂贵的操作,由于我拥有的大型项目集(150 万个项目),需要 30 分钟才能完成。
手动从弹性搜索中删除索引的最佳方法是什么?我打算使用 softdeletable 侦听器,因此当发生 softdelete 时,我会手动将其从索引中删除。但我不确定如何通过 elastica 做到这一点。
创建实体监听器:
<?php
namespace Acme\MainBundle\EventListener;
use Acme\MainBundle\Entity\InstagramShopPicture;
use Acme\MainBundle\Entity\InstagramShop;
class ElasticSearchSoftdeletableListener
{
private $container;
public function __construct($container)
{
$this->container = $container;
}
public function postSoftDelete(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof InstagramShopPicture) {
$type = 'picture';
} else if ($entity instanceof InstagramShop) {
$type = 'shop';
} else {
return;
}
$this->container->get("fos_elastica.listener.index.$type")->postRemove($args);
}
}
通过服务注册监听器:
softdeletable.listener:
class: Acme\MainBundle\EventListener\ElasticSearchSoftdeletableListener
arguments:
- @service_container
tags:
- { name: doctrine.event_listener, event: postSoftDelete }