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?

aaron
  • 39,695
  • 6
  • 46
  • 102
Sancho
  • 1,288
  • 2
  • 25
  • 50

2 Answers2

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:
            ...
Martijn
  • 15,791
  • 4
  • 36
  • 68
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.

Yohan G.
  • 1,176
  • 1
  • 7
  • 7