Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime is converted to string #964

Open
mjvanmiddelaar opened this issue Sep 3, 2020 · 0 comments
Open

DateTime is converted to string #964

mjvanmiddelaar opened this issue Sep 3, 2020 · 0 comments

Comments

@mjvanmiddelaar
Copy link

mjvanmiddelaar commented Sep 3, 2020

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

  • @es\Property(type="text")

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

  • @es\Property(type="date")

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant