0

我在使用教义 orm 的 config.yml 中创建了一个弹性搜索映射,问题是当我创建一个新文档时,索引会自动填充最顶层的对象,即“文档”,而不是任何子对象,例如“文件夹,作者,评论......”,有人可以建议我是否缺少任何标志或任何设置。下面是我的 Elastica 配置:

# Elastica Configuration
fos_elastica:
    clients:
        default: { host: localhost, port: 9200 }
    indexes:
        website:
            client: default
            index_name: docova
            types:
                documents:
                    mappings:
                        Doc_Title: ~
                        Description: ~
                        Date_Created: ~
                        Doc_Status: ~
                        Keywords: ~
                        folder:
                           type: "object"
                           properties:
                              id: ~
                              Library:
                                 type: "object"
                                 properties:
                                    id: ~
                        Author:
                           type: "object"
                           properties:
                              username: ~
                        Comments:
                           type: "object"
                           properties:
                              comment: ~
                        Form_Values:
                           type: "object"
                           properties:
                              Field_Value: ~
                        Bookmarks:
                           type: "object"
                           properties:
                              Target_Folder:
                                  type: "object"
                                  properties:
                                     id: ~
                        DocType:
                           type: "object"
                           properties:
                               id: ~
                               Doc_Name: ~
                        Attachments:
                           type: "object"
                           properties:
                              File_Name:
                              content:
                                 type: attachment 
                    persistence:
                        driver: orm
                        model: Docova\DocovaBundle\Entity\Documents
                        provider: ~
                        listener: ~
                        finder: ~

谢谢。

4

1 回答 1

0

我在这里找到了解决方案。 Symfony2 FOSElasticaBundle 更新与更新实体相关的所有实体的索引

注意:在我的 FOSElastica 版本中,Listener 不在 ORM 文件夹中,而是在 FOS\ElasticaBundle\Doctrine 中,并且参数已从 LifecycleEventArgs $eventArgs 更改为 \Doctrine\Common\EventArgs $eventArgs。

编辑:对于这种情况,您也必须覆盖 postPersist。

public function postPersist(\Doctrine\Common\EventArgs $eventArgs)
{

    $entity = $eventArgs->getEntity();


    if ($entity instanceof $this->objectClass && $this->isObjectIndexable($entity)) {

        $this->scheduledForInsertion[] = $entity;
        $this->inicializaPost();
        $this->objectPersisterPost->replaceOne($entity->getPost());
    }
}
于 2014-05-12T15:22:53.300 回答