Elasticsearch connector for Drupal 8 doesn't support facet date.
Fields date are stored in Elasticsearch service in 'strict_date_optional_time||epoch_second' format.
Dates are stored in milliseconds (example 1409231700000).
The facets module require date in timestamp seconds format (1409231700). The facets from elasticsearch values are broken.
Elasticsearch connector to Drupal 8 have a parseSearchFacets function in SearchApiElasticsearchBackend.php file but is never called. parseSearchFacets function contains the conversion from epoch milliseconds to seconds.
I created a patch to convert the date from epoch milliseconds format to seconds. The patch add parseDateFacets function.
The patch have the same behavior of Elasticsearch connector for Drupal 7. The date is divided by 1000.
Comments
Comment #2
artsakenos commentedSuccessfully applied the patch, on D8.8.2, module version 8.x-6.0-alpha2.
Comment #3
kmbremnerThis also fixes the year date facet for me with elasticsearch_connector 7-dev on D8.9
Comment #4
dealancer commentedWorks for me!
Comment #5
bircherrerolled the patch because it didn't apply for me any more
Comment #6
aron novakThe patch indeed works well for date facets.
Comment #7
aron novakI re-rolled the patch, also added a condition if
$termsis empty someway.Comment #8
BarisW commentedThanks for the patch! Works :)
Comment #9
marios anagnostopoulos commentedI moved the logic for this to the end of the block. There is an argument to be made about performance, but the actual overhead of this patch is minimal I think, and the code clarity will greatly improve, especially if more code is added to the logic checks above. Furthermore I moved the getIndexFields method outside of the helper function, since it does not need to run on every call. Otherwise the code is the same.
Comment #10
bluegeek9 commented+1 RTBC
Comment #12
sokru commentedCommitted the patch from #9. It seems to have lot of dead code, in attached patch I removed some of them, I'll appreciate if you're able to confirm the removals.
Comment #14
marios anagnostopoulos commentedIndeed the
addSearchFacetsIs not used anywhere.My guess is that it was required earlier by the search api backends, and when it was deprecated the module was not updated to reflect that.
In any case, I think it is safe to remove.
Comment #15
manuel.adanMoving to fixed since it is already committed and published into the last alpha4 release.