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?
You can't. One type per index only.
From Elasticsearch version 6.0 by default index doesn't allow multiple types per index. The better option is to always have one document type per index.
No, if you want to use a single index, you would need to define a single mapping that combines the fields of each document type. A better way might be to define separate indices on the same cluster for each document type.
Elasticsearch provides bulk api but it only supports index , create , delete and update operations over already created indexes. We cannot create multiple new indexes at once.
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:
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With