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

Howto transform complete entity? #1937

Open
mmaedler opened this issue Mar 19, 2024 · 0 comments
Open

Howto transform complete entity? #1937

mmaedler opened this issue Mar 19, 2024 · 0 comments

Comments

@mmaedler
Copy link

Hi,

first of all thank you so much for providing this awesome package! It made integrating our service with elastic a breeze!

However, at the moment I am looking for an elegant solution storing slightly modified copies of my entity in elastic search without having to define all the properties by hand.

But first some context: I have a rest service that provides product information. The main entity I am dealing with, is Product which in itself consists of numerous other related entites. Since these Product entities tend to be rather big in the end, I have decided not to return all of it as part of the response to requests to the service. Besides that I have created a DTO that contains both a subset of data that I have in the entity as well as some "computed" values based on what I have stored in other fields within the entity. Upon request the entity gets loaded, send through a custom converter class that maps the entity values to the one in the dto. Then the DTO gets serialized with JMS and returned as response. This logic already existed before I introduced Elastic (and fosElasticaBundle) to the stack.

What I want to do now is to apply the logic (entity -> converter -> model) before storing anything in elastic. This would speed up requests, since I can return the result completely from elastic. Question is: how can I hook into the ModelToElastic Transformation process provided by fosElasticaBundle and swap out the entity for the DTO and leverage my already existing serialization information before sending things off to Elastic?

Here's my current foselastica config for reference:

fos_elastica:
    clients:
        default: { url: '%env(ELASTICSEARCH_URL)%' }
    serializer:
        serializer: jms_serializer
#        callback_class: '@app.serializer_callback.product'
    indexes:
        product:
            index_name: '%env(ELASTICSEARCH_PRODUCT_BASE_INDEX)%'
            settings:
                index:
                    max_result_window: 200000
            persistence:
                driver: orm
                model: App\Entity\Product
                provider:
                  batch_size: 50
                finder: ~
#                model_to_elastica_transformer:
#                    service: app.model_to_elastica_transformer.product
            serializer:
                serialize_null: true

Up to now I tried two things:

  1. Custom modelToElasticaTransformer -> no success
  2. Custom SerializerCallback -> no success

How would you tackle this? Thanks!

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