我创建了elasticsearch索引:
$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);
}
Run Code Online (Sandbox Code Playgroud)
因此,添加了30个文档,现在我需要获取记录总数。这有效
$search_params= [
'index'=>'articles',
'type' => 'article',
];
$query = $es->search($search_params);
echo $query['hith']['total'];
Run Code Online (Sandbox Code Playgroud)
但是,正如我所阅读的那样,更有效的_count方法是使用直接计数方法。
我的问题是,我不了解如何_count在php API中实现?
尝试过:
$search_params= [
'index'=>'articles',
'type' => 'article',
'body' => [
'query' => ['_count'=>[] ]
]
];
$query = $es->search($search_params);
Run Code Online (Sandbox Code Playgroud)
和其他几种变体,但没有正确使用一种语法。
救命?
你有没有尝试过
$query = $es->count($search_params);
| 归档时间: |
|
| 查看次数: |
2592 次 |
| 最近记录: |