I have created elasticsearch index:
$es = Elasticsearch\ClientBuilder::create()->build();
$params = [
'index'=>'articles',
'type' => 'article'
];
for ($i=0; $i<30; $i++) {
$params['body'] = [ 'title'=>'title '.$i, 'body'=>'text '.$i ];
$response = $es->index($params);
}
So, 30 documents are added, now I need get total count of records. This works
$search_params= [
'index'=>'articles',
'type' => 'article',
];
$query = $es->search($search_params);
echo $query['hith']['total'];
But as I've read, more efficient is using straight counting _count
method.
My problem is, that I not understood how to implement _count
in php API?
tried:
$search_params= [
'index'=>'articles',
'type' => 'article',
'body' => [
'query' => ['_count'=>[] ]
]
];
$query = $es->search($search_params);
and several another variants, but don't get right one syntax.
Help?
Have you tried $query = $es->count($search_params);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments