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

Use of type "constant_keyword" #1914

Open
VinceSchlo opened this issue Jun 27, 2023 · 0 comments
Open

Use of type "constant_keyword" #1914

VinceSchlo opened this issue Jun 27, 2023 · 0 comments

Comments

@VinceSchlo
Copy link

VinceSchlo commented Jun 27, 2023

Hi everyone,

I'm currently trying to use the constant_keyword type to split my index by country.

I'm using v6.1.0 of FOSElasticaBundle

Here is an example of my indexe's declaration in fos_elastica.yaml:

fos_elastica:
    indexes:

        app.orders_be:
            index_name: '%env(ELASTICSEARCH_INDEX_PREFIX)%.orders_be'
            persistence:
                driver: orm
                model: App\Entity\CommandeAppro
                provider: ~
                listener:
                    defer: false
                    logger: true
                repository: App\Elastica\Repository\CommandeApproElasticaRepository
                elastica_to_model_transformer:
                    query_builder_method: createSearchQueryBuilder
                    ignore_missing: true
                finder: custom_transformed_finder.orders_be
            properties:
                <<: *order_properties
                country:
                    property_path: getCountryIsoCode
                    type: constant_keyword
                    value: BE
            settings:
                number_of_shards: 10

        app.orders_gb:
            index_name: '%env(ELASTICSEARCH_INDEX_PREFIX)%.orders_gb'
            persistence:
                driver: orm
                model: App\Entity\CommandeAppro
                provider: ~
                listener:
                    defer: false
                    logger: true
                repository: App\Elastica\Repository\CommandeApproElasticaRepository
                elastica_to_model_transformer:
                    query_builder_method: createSearchQueryBuilder
                    ignore_missing: true
                finder: custom_transformed_finder.orders_gb
            properties:
                <<: *order_properties
                country:
                    property_path: getCountryIsoCode
                    type: constant_keyword
                    value: GB
            settings:
                number_of_shards: 10

I use custom finder, so it is my services.yaml :

custom_transformed_finder.orders_gb:
       class: App\Finder\CustomTransformedFinder
       arguments:
           - '@fos_elastica.index.app.orders_gb'
           - '@fos_elastica.elastica_to_model_transformer.app.orders_gb'

   custom_transformed_finder.orders_be:
       class: App\Finder\CustomTransformedFinder
       arguments:
           - '@fos_elastica.index.app.orders_be'
           - '@fos_elastica.elastica_to_model_transformer.app.orders_be'

Each index is well created, with good data but the search isn't working that well. Indeed, after digging a bit into the code I think I found that the finder are related to the entity and not the index so on only the last one describe into the fos_elastica.yaml config file will be associated, ignoring/erasing the previous one.

If I search BE (Belgian) order, it works fine but if i try to search for GB (Great Britain) the BE finder is still used.

Am I wrong somewhere at using this ElasticSearch feature or is it unusable at this time due to the way the library is write ?

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

1 participant