duanfu2562 2015-03-11 15:33
浏览 451

如何使用Elastic Search php获取Elastic Search中的文档数量

I'm using the Elastic Search php client (this one). I'm trying to get the total number of documents in a type, but can't figure out how to do it. Any help would be greatly appreciated.

Here's what I've tried:

$params['index'] = $index_name;
$params['type'] = 'applicant';
$applicants_count = Es::count($params)["count"];

But that always seems to return 0.

  • 写回答

1条回答 默认 最新

  • dongle19863 2015-03-11 15:58
    关注

    Found the answer. This happened because I was trying to get the result in my test, which called count to soon after the document was indexed. I added the refresh command in between (Es::indices()->refresh(array("index" => $params["index"]));) and that solved the problem:

    $params['index'] = $index_name;
    $params['type'] = 'applicant';
    Es::indices()->refresh(array("index" => $params["index"]));
    $applicants_count = Es::count($params)["count"];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度