php - FosElasticaBundle:一个索引中的多种类型

标签 php symfony foselasticabundle

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

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

当我使用 fos:lastica:populate 时,出现错误:

Rejecting mapping update to [search_dev] as the final mapping would have more than 1 type: [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 种类型吗?

最佳答案

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

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

关于php - FosElasticaBundle:一个索引中的多种类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47379155/

相关文章:

php - symfony 事件监听器的执行时间是否也有限?

symfony - 您可以在同一实体的不同索引中定义两个或多个类型吗?

ElasticSearch RoutingMissingException

authentication - 在 Symfony2 单元测试中处理身份验证

symfony - Elasticsearch foselastica 存储库和 groupBy

javascript - 将 json 数组更新为 data-autocomplete 后,它不会更新 data-autocomplete 的值

php - 如何强制 mysqli 结果为字符串以支持遗留代码

php - 如何正确转义反斜杠以匹配单引号和双引号 PHP 正则表达式模式中的文字反斜杠

php - 如何重定向除登陆页面之外的子目录?

database - symfony2 doctrine.dbal.connection_factory 与 ssl?