Problem/Motivation
https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html
> Values for milliseconds-since-the-epoch and seconds-since-the-epoch must be non-negative. Use a formatted date to represent dates before 1970.
So the module fails to index any entities with a date field / timestamp before 1970.
Steps to reproduce
Create a date field on a content-type, add it to the index, create a new node with 1950.01.01. in the date field.
Proposed resolution
Use `formatted_date` instead of the epoch.
Data model changes
As I know, it won't change the data model, just how we store the date in ES, it's still a date for Elasticsearch.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 3189051-pre-epoch-dates-10.patch | 1.87 KB | aron novak |
| #8 | 3189051-pre-epoch-dates-8.patch | 1.69 KB | aron novak |
| #4 | 3189051-4.patch | 1.59 KB | sokru |
| #3 | 3189051-epoch-to-formatted-date-2.patch | 547 bytes | aron novak |
| #2 | 3189051-epoch-to-formatted-date-1.patch | 563 bytes | aron novak |
Comments
Comment #2
aron novakComment #3
aron novakActually the previous patch worked, but caused an Elasticsearch warning, let's see this one.
Comment #4
sokru commentedIf you look at Search API's Date type plugin , you see it will return a timestamp with default date field. There might be many services depending on date field as it is currently. I'd prefer adding new data type for date field.
Attached a patch with "Full date" type plugin that is able to handle pre-epoch dates.
Edit: Maybe this new plugin should be added on Search API module instead.
Comment #5
aron novak@sokru, https://www.drupal.org/files/issues/2021-03-18/3189051-4.patch seems to be the right direction, but I receive this during indexing:
So it seems in my case, it tried to index the data as a timestamp simply.
Comment #6
sokru commentedDid you change your field type to full_date and cleared the index?
Works on my machine: https://github.com/KalleVuorjoki/drupal-elasticsearch/tree/3189051-pre-e...
Comment #7
aron novakSo the difference is that in my failing case, I try to index "created", you index a date field.
Checking how to resolve this.
Comment #8
aron novakI could tackle it easily in
\Drupal\elasticsearch_connector\Plugin\search_api\data_type\FullDateDataType::getValueComment #9
sokru commentedI think we need to rephrase the description from "Represents points in time" to something like, "Formatted date. Use for pre-epoch dates (dates before 1st of January 1970)".
Comment #10
aron novakComment #11
sokru commentedLooks good to me.
Comment #13
sokru commentedChanged the deprecated
DATE_ISO8601toDATE_ATOM. That makes dates a bit different:I hope that's fine.
Comment #15
baysaa commentedDoes this affect 8.0.x?
I'm getting
Comment #16
sokru commentedThe upgrade path didn't caught this, should create a new issue for providing the upgrade path.
Using the "string" plugin provides following date
Which I hope is sufficient.