ElasticsearchBundle
ElasticsearchBundle copied to clipboard
Multiple indexes for one Document
As I see it there is no chance to create more than one index using the same document type in version 6.0. Until now I have used my "Package" document in multiple indexes like "package_de_chf" or "package_fr_chf" (country/currency pairs). This was a performance gain since I never needed these entries to be mixed.
I've tried it like this. But obviously this won't work since only one
IndexService
is being generated with the name being the same as the classname.
Is is possible we could use the alias as service names? Maybe add an optional parameter alias_as_service_name=true
for the annotation?
I am willing to create a PR if there is a chance it will get merged ;)
There is no way to do that with annotations but you can do that with a YAML config. If you won't find how will write an example later.
I am not sure if you meant I could already do that or that it can be made to work with YAML config? As I have seen in MappingPass
, the service name is fixed to the class name so I assume the latter.
BTW: It would also be possible with annotations if we introduce a new one:
/**
* @ES\MultiIndex(indexes={
* @ES\Index(alias="package_de_chf")
* @ES\Index(alias="package_fr_chf")
* @ES\Index(alias="package_de_eur")
* @ES\Index(alias="package_fr_eur")
* })
*/
When using this annotation we could automatically use the alias
as the service name since it wouldn't be possible to use the class name anyway.
@saimaz Can you elaborate? I am still not sure what's the case here.
@saimaz I tried to figure it out myself again but I can't seem to find a solution since every Namespace
can only be used once in the yaml config.
@saimaz I just spent some time creating an alternative to the current config. I had an idea how we wouldn't loose BC:
ongr_elasticsearch:
indexes:
'package_de_chf':
class: Weekend4two\BackendBundle\Document\Package
hosts:
- '%env(ELASTICSEARCH_ENDPOINT)%'
'package_fr_chf':
class: Weekend4two\BackendBundle\Document\Package
hosts:
- '%env(ELASTICSEARCH_ENDPOINT)%'
Weekend4two\BackendBundle\Document\PackageIsochrone:
hosts:
- '%env(ELASTICSEARCH_ENDPOINT)%'
When using the class
property, the created index will use the name of the index attribute (ongr.es.package_de_chf
). This way we can create multiple indexes with the same class
.
An already working alternative would be if I created an abstract class with all the contents of Package
and create a class which extends the abstract (PackageDeChf extends Package
). I do not really think this is a good solution and being able to configure multiple services/indexes of the same class is a must.
What do you think? I am sill interested in creating a PR for such a change since.