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.
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"];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.