问题:如何在elasticsearch7中获取索引的项数?

使用弹性搜索 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

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

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

欢迎大家访问Elastic 中国社区。由Elastic 资深布道师,Elastic 认证工程师,认证分析师,认证可观测性工程师运营管理。

更多推荐