Elasticsearch不再返回正确的文档计数,除非我再次使用_count API进行搜索

pb3skfrl  于 2023-05-16  发布在  ElasticSearch
关注(0)|答案(1)|浏览(142)

我有一个elasticsearch 7.10.2服务器,有280万个文档

# curl IP:9200/_count
{"count":2819000,"_shards":{"total":2,"successful":2,"skipped":0,"failed":0}}

搜索请求显示仅存在10K行,

# curl IP:9200/bigdata/_search?pretty -d @/root/query -H 'Content-Type: application/json'
{
  "took" : 4,
  "timed_out" : false,
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },
    "max_score" : 0.98024774,
    "hits" : [ ... ],
  }
}

但实际上有140万个匹配

# curl IP:9200/bigdata/_count?pretty -d @/root/query -H 'Content-Type: application/json'
{
  "count" : 1442357,
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "skipped" : 0,
    "failed" : 0
  }
}

我的问题是,我必须进行两次API调用才能获得过滤后的行数,如何通过一次API调用同时获得这两个参数?

q5iwbnjs

q5iwbnjs1#

从ES 7.0.0开始,hits.count值不再是整数值,而是object that indicates the approximate hits count,以防有超过10000个结果(即默认值track_total_hits)。如果您想增加计数,以达到准确的结果计数,或者如果您想保留旧的语义,您可以简单地使用rest_total_hits_as_int=true发送查询,则可以更改此值。

curl IP:9200/bigdata/_search?pretty&rest_total_hits_as_int=true -d ...

相关问题