ElasticsearchBundle icon indicating copy to clipboard operation
ElasticsearchBundle copied to clipboard

Issue with falsy value in setting mappings

Open tung-huynh opened this issue 4 years ago • 0 comments

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

tung-huynh avatar Mar 02 '20 15:03 tung-huynh