FosElasticaBundle: how to dump the actual JSON pas

2019-09-10 23:31发布

问题:

I am using FosElasticaBundle in a Symfony project. I configured my mappings but I get exception "expected a simple value for field [_id] but found [START_OBJECT]]".

I'd like to see the actual JSON created by FosElasticaBundle so I can directly test it against my ElasticSearch server, and understand more about the exception.

According to FosElastica documentation, everything should be logged when debug mode is enabled (i.e. in DEV environment) but I can't see this happening; I only see Doctrine queries, but no JSON.

How can I dump the JSON created by FosElasticaBundle?

Update: mappings

# FOSElasticaBundle
fos_elastica:
    clients:
        default: { host: %elasticsearch_host%, port: %elasticsearch_port%, logger: false }
    indexes:
        app:
            types:
                user:
                    mappings:
                        name: ~
                        surname: ~
                    persistence:
                        driver: orm
                        model: AppBundle\Entity\User
                        provider: ~
                        listener: ~
                        finder: ~

回答1:

I think you should only set your logger to true instead of false

fos_elastica:
    clients:
        default:
            host: %elasticsearch_host%
            port: %elasticsearch_port%
            logger: true                        <---- set true here
    ...