[英]PHP Elasticsearch GET value of a field from all documents in index
[英]elasticsearch get documents total count in index using php API
我创建了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);
}
因此,添加了30个文档,现在我需要获取记录总数。 这有效
$search_params= [
'index'=>'articles',
'type' => 'article',
];
$query = $es->search($search_params);
echo $query['hith']['total'];
但是,正如我所阅读的,更有效的方法是使用直接计数_count
方法。
我的问题是,我不了解如何在php API中实现_count
?
尝试:
$search_params= [
'index'=>'articles',
'type' => 'article',
'body' => [
'query' => ['_count'=>[] ]
]
];
$query = $es->search($search_params);
和其他几种变体,但没有正确使用一种语法。
救命?
您是否尝试过$query = $es->count($search_params);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.