存储库删除查询后,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"
},

¿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.

If you use doctrine commands like update or delete, the FOSElastica's listeners are not run. In this case, you should exploit the fos:elastica:populate command