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);
https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/ElasticsearchPHP_Endpoints.html#Elasticsearch_Clientcount_count
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With