Skip to content

Issue with falsy value in setting mappings #923

@tung-huynh

Description

@tung-huynh

I see that we had the issue with the falsy value caused by the misuse of array_filter function.

For my case i am using this mapping

/**
 * @var string
 * @ES\Property(type="text", settings={"index"=false})
 */
 private $url;

The actual result which is not expected (please ignore the nested type)

{
    "properties": {
        "url": {
            "type": "text"
        }
     }
}

The expected result should be

{
    "properties": {
        "url": {
            "type": "text",
            "index": false #<-----this_is_what_we_want
        }
     }
}

I believe the root cause was this line https://github.com/ongr-io/ElasticsearchBundle/blob/v6.2.2/Mapping/DocumentParser.php#L169

When changing it to this, it works fine

$mapping[$annotation->getName() ?? Caser::snake($name)] = array_filter(
    $fieldMapping,
    function ($value) {
        return null !== $value;
    }
);
- PHP version: 7.3
- Elasticsearch version: 6.x
- Bundle version: 6.x
- Symfony version: 5.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions