你不会是程序猿吧?

ElasticSearch Count API 和 track_total_hits 两者的区别是什么?

Elasticsearch | 作者 hapjin | 发布于2019年10月17日 | 阅读数:13189

我想计算:某个查询条件(比如exists-query)下文档的总数,看了下ES官方文档:count api :


Gets the number of matches for a search query.


返回符合查询条件的文档数量,应该能满足需求。
但是,我又看到了另一个参数:track-total-hits,这里面提到:某个查询条件下的total hits是不准确的,因为它没有:visiting all matches。而 track_total_hits 提供了一个下界来保证 符合查询条件 的文档数量的准确性。


Generally the total hit count can't be computed accurately without visiting all matches, which is costly for queries that match lots of documents. The track_total_hits parameter allows you to control how the total number of hits should be tracked. 


我的疑问是:
count api 得到的 符合查询条件的文档 数量一定是准确的吧?如果是准确的话,那么它应该 visiting all matches了,那是不是说明:count api 是一个很耗时的操作吧?那么 我要计算:符合某个查询条件下的文档的准确数量时,使用 count api 好呢?还是 使用 track_total_hits 好呢?有什么坑要注意的么?
 
参考链接:Do not compute hit counts by default
已邀请:

要回复问题请先登录注册