I'm trying to use Elasticsearch with a PHP client. However, when I construct a simple query, it gives drastically different results against the same index than what I believe is the equivalent query via Curl or Python. I.e., the results are entirely unrelated to the query - seems like a random chunk of data. It also returns these same results regardless of the value of the parameter (last name) I send. Here is the PHP code:
<?php
require 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;
$client = ClientBuilder::create()->build();
$params = [
'index' => 'directory',
'body' => [
'query' => [
'match' => [
'last_name' => 'ely'
]
]
]
];
$response = @$client->search($params);
print_r($response);
?>
And here is the Curl equivalent, that returns accurate results:
http://localhost:9200/directory/_search?q=last_name:ely
Thanks in advance for any suggestions!
The error you're getting comes from this line in SmartSerializer.php
$data = json_encode($data, JSON_PRESERVE_ZERO_FRACTION);
You can see that the second argument JSON_PRESERVE_ZERO_FRACTION
has been added in this commit, which also requires PHP version 5.6.6
So the problem comes from the fact that you're using the latest version of elasticsearch-php which needs PHP 5.6.6, but your PHP version is lower than that, and hence, JSON_PRESERVE_ZERO_FRACTION
does not exist in your PHP version.