FosElasticaBundle: multiple types in one index
Asked Answered
D

2

6

I need to build a multiple-entity search.

I don't want every T1, then every T2.

When I use fos:lastica:populate, I get an error:

Rejecting mapping update to [search_dev] as the final mapping would have more than 1 type: [t1, t2]

My mapping:

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

My service:

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

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

Did I miss something? Can I map 2 types in 1 index?

Diann answered 19/11, 2017 at 16:31 Comment(0)
K
4

I was looking for a way to get products and categories and got the same error. It worked when I moved it around and made multiple indexes:

fos_elastica:
  clients:
    default: { host: localhost, port: 9200 }
  indexes:
    products:
      types:
        product:
          properties:
            ...
          persistence:
            ...
    categories:
      types:
        category:
          properties:
            ...
          persistence:
            ...
Kea answered 1/5, 2018 at 7:25 Comment(3)
This is much more helpful than the other answer thanks.Geometrician
Thanks for the helpful answer. In case it's still handy, would you be willing to post the PHP part of this?Dayna
I no longer have access to that code, but I had used their example as basis, worked pretty quick. And if you like answers on SO, dont forget to upvote them :)Kea
K
3

That's not related to Elastica, but Elasticsearch 6.0 : https://www.elastic.co/guide/en/elasticsearch/reference/6.0/removal-of-types.html.

I have the same issue and didn't find an easy way to map multiple doctrine models in a single index for now.

Kearney answered 18/12, 2017 at 15:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.