2
votes

I installed ElasticSearch 6 with their Docker image and everything work well.

Then I installed and configured FOSElastica like the doc said.

This is the following config of fos_elastica

fos_elastica:
    clients:
        default: { host: '%env(ELASTICSEARCH_HOST)%', port: '%env(ELASTICSEARCH_PORT)%' }
    serializer:
        serializer: jms_serializer
    indexes:
        app:
            client: default
            types:
                user:
                    serializer:
                        groups: [elastica]
                    persistence:
                        driver: orm
                        model: AppBundle\Entity\User
                        provider: ~
                        listener: ~
                        finder: ~

And the model of my User entity to give the elastica serializer group to some field

AppBundle\Entity\User:
    exclusion_policy: ALL
    properties:
        firstname:
            expose: true
            groups: [elastica, list, details]
        lastname:
            expose: true
            groups: [elastica, list, details]
        locale:
            expose: true
            groups: [elastica, details]

The serializer is working well for my API and is well configurated

 jms_serializer:
    metadata:
        auto_detection: true
        directories:
            AppBundle:
                namespace_prefix: 'AppBundle'
                path: '%kernel.project_dir%/config/serializer'

When I'm trying to populate ElasticSearch I get, I think a bad serialization error

In Http.php line 181:

[Elastica\Exception\ResponseException]                                              
Malformed action/metadata line [3], expected START_OBJECT but found [VALUE_STRING]

I tried to set field typing using properties.type config in the fos_elastica configuration without success.

I tried with another entity and I get the same error.

I have already work with FOSElasticaBundle ~1year ago on the same project and population was working...

I didn't success to find where is the problem, if there is a JMSSerializer/FOSElastica bug or a misconfig

Did I miss something in the configuration ? Do you already had this issue ?

2
Any solution Bro ? - famas23
This error is due to JSON_PRETTY_PRINT and does exactly the same with symfony serializer. Remove it and it should work - Jérôme
Grezat solved thank you so mush ^^ - famas23

2 Answers

1
votes

I had a similar problem. Here are the original elastic configs (which gave this error).

fos_elastica:
clients:
    default: { host: '%env(ELASTICSEARCH_HOST)%', port: '%env(ELASTICSEARCH_PORT)%' }
serializer:
    serializer: jms_serializer
indexes:
    app:
        finder: ~
        types:
            goods:
                properties:
                    name: { type: text }
                    brand: { type: text }
                    cost: { type: float }
                    category:
                        type: "object"
                        properties:
                          id: ~
                          name: ~
                    goodsDescriptions:
                        type: "object"
                        properties:
                          id: ~
                          name: ~
                          description: ~
                persistence:
                    driver: orm
                    model: App\Entity\Goods\Goods
                    provider: ~
                    finder: ~
                    repository: App\SearchRepository\GoodsRepository

However, I climbed inside the vendor foselastic for a long time and noticed that the data for adding it took based on jms_serializer, which was obvious, but at that time I thought otherwise. By removing this serialization and it was worked. We have different settings, but maybe it will give you an idea.

1
votes

To avoid this error just remove the

JSON_PRETTY_PRINT

from your JMS/Symfony Serializer config.