ongr-io / ElasticsearchBundle

Symfony bundle for Elasticsearch with steroids
MIT License
313 stars 189 forks source link

DateTime is converted to string #964

Open mjvanmiddelaar opened 4 years ago

mjvanmiddelaar commented 4 years ago

In my class i have these properties (and the setters and getters)

    /**
     * @ES\Property(type="date")
     */
    private $publicationDate;

    /**
     * @ES\Property(type="date")
     */
    private $expirationDate;

When I supply a DateTimeInterface, this works when the object is an instance of DateTimeImmutable. However, when this is an instanceof DateTime, the object is converted to string on to the following line: https://github.com/ongr-io/ElasticsearchBundle/blob/master/Mapping/Converter.php#L66

The converter does not take into account my annotation, someone could use

In this case it should be converted to string, but when i use

It should not.

I would suggest to leave it up to the developer to decide to use either of one of them and supply the value in the correct format, and remove the DateTime conversion from this converter. Removing the line from the converter however, would be a BC.

The error that occurs in my case is:

HTTP 500 Internal Server Error
{"took":4,"errors":true,"items":[{"index":{"_index":"publication-1596714879","_type":"_doc","_id":"e7f3f455-14d0-4c63-a8dd-e7d199c5a384","status":400,"error":{"type":"mapper_parsing_exception","reason":"object mapping for [publication_date] tried to parse field [publication_date] as object, but found a concrete value"}}}]}
- PHP version 7.3.18 
- Elasticsearch version: 7.4.2
- Bundle version: 7.0.3
- Symfony version: 5.1.3