duanran3115 2017-08-17 12:39
浏览 60

存储库删除查询后,Symfony ElasticSearch不会同步

I am using foselastica and I get the error "Cannot find corresponding Doctrine objects (0) for all Elastica results (7). IDs: 52, 51, 50, 48, 49, 47, 46" after a delete query in the repository, however the query does delete in mysql database:

class CandidatesRepository extends EntityRepository
{
    public function candidatesFileimportDelete($id)
    {
        $q = $this->createQueryBuilder('c')->delete()
            ->where('c.fileImportId = :id')->setParameter('id', $id);
        return $q->getQuery()->getResult();
    }
}

When I use a doctrine remove it does sync and all the candidates are removed from ES

$candidates = $this->getDoctrine()
    ->getRepository(Candidates::class)
    ->findAll();


foreach($candidates as $candidate){
    $em = $this->getDoctrine()->getManager();
    $em->remove($candidate);
    $em->flush();
}

code samples:

entity

    /**
     * @ORM\Entity
     * @ORM\Table(name="candidates_user")
     * @ORM\Entity(repositoryClass="CandidatesBundle\Entity\Repository\CandidatesRepository")

     */
    class Candidates
    {
// filled with privatre properties and public getters and setters
    } 

config.yml

fos_elastica:
clients:
    default: { host: localhost, port: 9200 }
indexes:
    candidates:
        types:
            candidates:
                mappings:
                    id: { type: integer }
                    name: { type: string }
                    job: { type: string }
                    approached: {type: integer}
                    level: {type: string }
                    skills: {type: string}
                    email: {type: string}
                    mobile: {type: string}
                    city: {type: string}
                    province: {type: string}
                    country: {type: string}
                    linkedinUrl: {type: string}
                    addedCompany: {type: string}
                    note: {type: string}
                    dateAdded: {type: date}
                    deleted: {type: integer }
                    dateDeleted: {type: date}
                    platform: {type: string}
                    fileImportId: {type: integer}

                persistence:
                    driver: orm
                    model: CandidatesBundle\Entity\Candidates
                    provider:
                       batch_size: 10
                       debug_logging: false
                    listener:
                        is_indexable_callback: "isSearchable"
                        insert: true
                        update: true
                        delete: true
                    finder: ~
                    repository: CandidatesBundle\Entity\Repository\CandidatesRepository

part of my elastic service to gather candidates

    /**
 *  Search all active candidates
 */
public function getAllCandidates($request, $showDeleted = false)
{

    $finder = $this->container->get('fos_elastica.finder.candidates.candidates');
    $boolQuery = new \Elastica\Query\BoolQuery();

    if (!empty($request->get('s')) && $request->get('c')) {
        if (in_array($request->get('c'), self::SEARCH_CATEGORIES, true)) {
            $boolQuery->addMust(
                $this->setQueryString(array($request->get('c')), $request->get('s'))
            );
        }
    }

    if ($showDeleted == false) {
        $boolQuery->addMust(
            $this->setTerm('deleted', array(0))
        );
    }

    $query = $this->setSort($boolQuery, array('dateAdded' => array('order' => 'asc')));

    if (!empty($request->get('sort')) && $request->get('cat')) {
        if (in_array($request->get('cat'), self::CAT, true) &&
            in_array($request->get('sort'), self::SORT)) {
            $query = $this->setSort($boolQuery, array($request->get('cat') => array('order' => $request->get('sort'))));
        }
    }

    $candidates = $finder->find($query, 3000);
    return $candidates;
}

required bundles:

"require": {
    "php": ">=5.5.9",
    "doctrine/doctrine-bundle": "^1.6",
    "doctrine/doctrine-migrations-bundle": "1.2",
    "doctrine/orm": "^2.5",
    "friendsofsymfony/elastica-bundle": "^4.0",
    "friendsofsymfony/user-bundle": "~2.0",
    "gedmo/doctrine-extensions": "^2.4",
    "incenteev/composer-parameter-handler": "^2.0",
    "liuggio/excelbundle": "^2.1",
    "sensio/distribution-bundle": "^5.0.19",
    "sensio/framework-extra-bundle": "^3.0.2",
    "symfony/monolog-bundle": "^3.1.0",
    "symfony/polyfill-apcu": "^1.0",
    "symfony/swiftmailer-bundle": "^2.3.10",
    "symfony/symfony": "3.3.*",
    "twig/twig": "^1.0||^2.0"
},
"require-dev": {
    "doctrine/doctrine-fixtures-bundle": "^2.3",
    "sensio/generator-bundle": "^3.0",
    "symfony/phpunit-bridge": "^3.0"
},
  • 写回答

2条回答 默认 最新

  • dongshuxi3105 2017-08-17 12:52
    关注

    ¿Could it be that you must perform deletions using manager to trigger sync events that FosElastica listens to? If so, you sould get te entities using your query and then delete usign $manager->remove()

    Not sure 100% but I'm currently using FosElastica and it keeps ES updated and I'm not doing deletions using query builder.

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口