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

marco.aresu created an issue. See original summary.

artsakenos’s picture

Version: 8.x-7.0-alpha2 » 8.x-6.0-alpha2
Status: Needs review » Reviewed & tested by the community

Successfully applied the patch, on D8.8.2, module version 8.x-6.0-alpha2.

kmbremner’s picture

Version: 8.x-6.0-alpha2 » 8.x-7.x-dev

This also fixes the year date facet for me with elasticsearch_connector 7-dev on D8.9

dealancer’s picture

Works for me!

bircher’s picture

StatusFileSize
new1.87 KB

rerolled the patch because it didn't apply for me any more

aron novak’s picture

The patch indeed works well for date facets.

aron novak’s picture

I re-rolled the patch, also added a condition if $terms is empty someway.

BarisW’s picture

Thanks for the patch! Works :)

marios anagnostopoulos’s picture

I 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.

bluegeek9’s picture

+1 RTBC

sokru’s picture

StatusFileSize
new9.72 KB

Committed 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.

  • sokru committed 899f6098 on 8.x-7.x
    Issue #3096887 by sokru: Update documentation
    
marios anagnostopoulos’s picture

Indeed the addSearchFacets Is 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.

manuel.adan’s picture

Status: Reviewed & tested by the community » Fixed

Moving to fixed since it is already committed and published into the last alpha4 release.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.