Cannot start with Elasticsearch and PHP

Hi friends,
already 3 days I am fighting with tutorials for Elasticsearch, how to install it, how to use it with php etc.

Currently I have elasticsearch on server (debian 8) hopefully working, but I can't work with php.

I use just small part of code:

require 'vendor/autoload.php';

$client = Elasticsearch\ClientBuilder::create()->build();

$params = [
'index' => 'my_index',
'type' => 'my_type',
'id' => 'my_id',
'body' => ['testField' => 'abc']

$response = $client->index($params);

And I get:

Notice: Use of undefined constant JSON_PRESERVE_ZERO_FRACTION - assumed 'JSON_PRESERVE_ZERO_FRACTION' in /var/www/nnc/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Serializers/SmartSerializer.php on line 30

Warning: json_encode() expects parameter 2 to be long, string given in /var/www/nnc/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Serializers/SmartSerializer.php on line 30

Fatal error: Uncaught exception 'Elasticsearch\Common\Exceptions\BadRequest400Exception' with message '{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse, document is empty"}],"type":"mapper_parsing_exception","reason":"failed to parse, document is empty"},"status":400}' in /var/www/nnc/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:681 Stack trace: #0 /var/www/nnc/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(659): Elasticsearch\Connections\Connection->tryDeserializeError(Array, 'Elasticsearch\C...') #1 /var/www/nnc/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(579): Elasticsearch\Connections\Connection->tryDeserialize400Error(Array) #2 /var/www/nnc/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(261): Elasticsearch\Connections\Connection->process4xxError(Array, Array, Array) #3 /var/www/nnc/vendor/react/promise/src/FulfilledPromise.php(25): Elasticsearch\ in /var/www/nnc/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php on line 682

I am running on debian 8 Jessie, php 5.6.27 (newest in repository).

Are you able to help me what's the trouble?

Same here, I had to revert to 3.3.0

$ php -v
PHP 5.6.29-0+deb8u1 (cli) (built: Dec 13 2016 16:02:08) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

Is JSON_PRESERVE_ZERO_FRACTION missing from this PHP package?

Same problem here!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.