doufunuo4787
2017-01-01 07:14
浏览 62
已采纳

Elasticsearch - 与不同客户的不同结果

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!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • du8589840 2017-01-02 06:55
    已采纳

    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.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题