Skip to content

Elasticsearch Denormalizer returns null for fields composed of two ore more words (ex. firstName) #4053

Description

@imaximius

API Platform version(s) affected: 2.6.3

Description
As mentioned in summary there is an issue with getting data form Elasticsearch. It reproduced when I tried to get data for fields that composed of several words (ex. firstName, createdAt etc.) Result the same for jsonld and graphql normalizers and for nested objects as well.

How to reproduce

  1. Enable support for Elasticsearch
  2. Create model and field with two words name
  3. Store some data
  4. Try to get data by using jsonld or graphql formats
  5. Result for fields with two words name will be empty

Possible Solution
There is could be a bug with comparing allowedAttributes to attributes from ES result. Method getAllowedAttributes of AbstractObjectNormalizer returns allowed attributes in camel case whereas attributes in ES source wrote in snake_case

Activity

  1. changed the title [-]Elasticsearch Denormlizer returns null for fields composed of two ore more words (ex. firstName)[/-] [+]Elasticsearch Denormalizer returns null for fields composed of two ore more words (ex. firstName)[/+] on Feb 11, 2021
  2. meyerbaptiste commented on Feb 11, 2021

    @meyerbaptiste
    Member

    I think we definitely have a problem with documents with fields in snake case (cf. api-platform/docs#1204 (comment)). I will investigate this in the next few weeks.

  3. imaximius commented on Feb 11, 2021

    @imaximius
    Author

    Thanks a lot. I'll be waiting

  4. lwillems commented on Mar 2, 2022

    @lwillems

    @imaximius i can confirm issue comes from getAllowedAttributes comparison (snakeCase in ES vs CameCasel in models)
    @meyerbaptiste got ideas to solve this ?

    Regards

  5. added theissue type on May 29, 2026
  6. soyuka commented on Jun 11, 2026

    @soyuka
    Member

    This has been resolved: InnerFieldsNameConverter (src/Elasticsearch/Serializer/NameConverter/InnerFieldsNameConverter.php) now converts snake_case ES fields back to camelCase during denormalization, and tests/Functional/Elasticsearch/ReadTest.php covers multi-word fields like firstName/lastName. Verified on current 4.3 HEAD. Closing as fixed — please reopen if you still reproduce on a recent release.

  7. soyuka commented on Sep 30, 2026

    @soyuka
    Member

    My previous comment was wrong, sorry: nothing converts snake_case fields by default, the InnerFieldsNameConverter fallback never applies and the functional tests use camelCase fields. See #8470.

    To map snake_case documents you need to configure a name converter, the docs are updated in api-platform/docs#2349. Note that the converter also applies to the field names used by filters and sorting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions