elasticsearch - 如何在elasticsearch7中获取索引的项目数?

标签 elasticsearch

使用elasticsearch 6.7时,

GET /indexName/_search 

返回索引的确切总数:

"hits" : {
    "total" : 1527325,
    "max_score" : 1.0,
    ...}

但在 elasticsearch 7.0 中

GET /indexName/_search

得到:

"hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },

这意味着总数大于10000,那么我如何才能获得7.0中索引的确切总数?

最佳答案

从 ES 7.0.0 开始,您需要使用 track_total_hits参数:

GET /indexName/_search?track_total_hits=true

您也可以添加 rest_total_hits_as_int参数,如果您想恢复与 7 之前版本相同的格式(将在 ES 8 中删除的临时参数):

GET /indexName/_search?track_total_hits=true&rest_total_hits_as_int=true

关于elasticsearch - 如何在elasticsearch7中获取索引的项目数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56238141/

相关文章:

templates - 尽管禁用了dynamic_mapping,但Logstash仍继续创建字段

Elasticsearch - 副本在重新打开索引 INDEX_REOPENED 错误后未分配

sorting - Elasticsearch - 将单个结果推到顶部

java - 在 Spring java 框架中使用 ElasticSearch 的最佳方式

elasticsearch - 将嵌套文档中的特定字段作为一个文档进行搜索

perl - 如何在MetaCPAN上进行滚动搜索?

ElasticSearch NEST 执行原始查询 DSL

elasticsearch - 没有在字段上声明的类型 [join] 的处理程序

elasticsearch - 如何将 Elasticsearch 从1.7.x升级到7.0?

amazon-web-services - AWS Elasticsearch:如何将位置{lat:float,lon:float}的映射类型更改为geo_point