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

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备