【问题标题】:FosElasticaBundle: multiple types in one indexFosElasticaBundle:一个索引中的多种类型
【发布时间】:2017-11-19 16:31:01
【问题描述】:

我需要构建一个多实体搜索。

我不想要每个 T1,然后是每个 T2。

当我使用fos:lastica:populate 时,我得到一个错误:

拒绝对 [search_dev] 的映射更新,因为最终映射将有超过 1 种类型:[t1, t2]

我的映射:

fos_elastica:
   clients:
       default:
           host: %elastic_host%
           port: %elastic_port%
   indexes:
       search:
           finder: ~
           client: default
           index_name: search_%kernel.environment%
           types:
               t1:
                   indexable_callback: 'getEnabled'
                   properties:
                       id:
                          type: integer
                       name: ~
                   persistence:
                       driver: orm
                       model: AppBundle\Entity\T1
                       finder: ~
                       listener:
                          logger: true
                       elastica_to_model_transformer:
                          ignore_missing: true
               t2:
                   indexable_callback: 'getEnabled'
                   properties:
                       id:
                          type: integer
                       name: ~
                   persistence:
                       driver: orm
                       model: AppBundle\Entity\T2
                       finder: ~
                       listener:
                          logger: true
                       elastica_to_model_transformer:
                          ignore_missing: true

我的服务:

$search = $this->indexManager->getIndex('search')->createSearch();
$search->addType('t1');
$search->addType('t2');
$resultSet = $search->search($query);

$results = $this->modelTransformer->transform($resultSet->getResults());

我错过了什么吗?我可以在 1 个索引中映射 2 种类型吗?

【问题讨论】:

    标签: php symfony foselasticabundle


    【解决方案1】:

    我正在寻找一种获取产品和类别的方法,但遇到了同样的错误。当我移动它并制作多个索引时它起作用了:

    fos_elastica:
      clients:
        default: { host: localhost, port: 9200 }
      indexes:
        products:
          types:
            product:
              properties:
                ...
              persistence:
                ...
        categories:
          types:
            category:
              properties:
                ...
              persistence:
                ...
    

    【讨论】:

    • 这比其他答案更有帮助,谢谢。
    • 感谢您的帮助。如果它仍然很方便,您愿意发布其中的 PHP 部分吗?
    • 我无法再访问该代码,但我以他们的示例为基础,工作得很快。如果你喜欢关于 SO 的答案,别忘了给他们点赞 :)
    【解决方案2】:

    这与 Elastica 无关,但与 Elasticsearch 6.0 相关:https://www.elastic.co/guide/en/elasticsearch/reference/6.0/removal-of-types.html

    我遇到了同样的问题,目前还没有找到一种简单的方法来将多个学说模型映射到一个索引中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-11
      • 1970-01-01
      • 2019-05-06
      • 1970-01-01
      • 2021-09-06
      • 1970-01-01
      相关资源
      最近更新 更多