Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple indexes for one Document #902

Open
toooni opened this issue Dec 12, 2019 · 5 comments
Open

Multiple indexes for one Document #902

toooni opened this issue Dec 12, 2019 · 5 comments

Comments

@toooni
Copy link
Contributor

toooni commented Dec 12, 2019

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.

image
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 ;)

@saimaz
Copy link
Member

saimaz commented Dec 12, 2019

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.

@toooni
Copy link
Contributor Author

toooni commented Dec 12, 2019

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.

@toooni
Copy link
Contributor Author

toooni commented Jan 7, 2020

@saimaz Can you elaborate? I am still not sure what's the case here.

@toooni
Copy link
Contributor Author

toooni commented Feb 7, 2020

@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.

@toooni
Copy link
Contributor Author

toooni commented Feb 8, 2020

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants