Invertus / elasticsearch

Elasticsearch® module for PrestaShop that makes search and filter significantly faster.
47 stars 21 forks source link

Indexing fails silently with switching to Elasticsearch 5 library #1

Closed gnanet closed 6 years ago

gnanet commented 7 years ago

Distributor ID: Debian Release: 8.6 PHP version: 5.6.27-0+deb8u1 php5-json version: 1.3.6-1

EDIT: The issue of missing constants was resolved in php5-json version 1.3.7, the docs also contain the php version requirement

Followed the instructions about switching to Elasticsearch 5 library, module was installed, but index creation ignored shard and replica parameters, and reindexing products failed also with notable reason.

error_log contained:

PHP message: PHP Warning: json_encode() expects parameter 2 to be long, string given in MANGLED_PATH/modules/brad/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Serializers/SmartSerializer.php on line 30

The mentioned line 30 contained:

$data = json_encode($data, JSON_PRESERVE_ZERO_FRACTION);

A quick search pointed to a change in Elasticsearch 5 library described in Pull Request 481

Based on the error message, i assumed that JSON_PRESERVE_ZERO_FRACTION was not a reserved constant, and replacing it with the numeric value referred in the comment of the PHP manual about JSON Predefined Constants resolved the issues.

These constants should be already predefined since PHP 5.6.6, but according to a thread on the Debian forums it was not the case with PHP 5.6.13 either, also there seems no bugreports about this.

I agree that fixing of this issue should be done by upstream, but if any user is facing this issue, my report can help, to work around it.

sarjon commented 7 years ago

Hi, thanks a lot for your contribution and providing a great explanation!

gnanet commented 7 years ago

I want to extend the search with textual content from Product datasheet PDF-files, and i will try to extend this great piece of software, i think i will fork and start working on it