我有一个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调用同时获得这两个参数?
1条答案
按热度按时间q5iwbnjs1#
从ES 7.0.0开始,
hits.count
值不再是整数值,而是object that indicates the approximate hits count,以防有超过10000个结果(即默认值track_total_hits
)。如果您想增加计数,以达到准确的结果计数,或者如果您想保留旧的语义,您可以简单地使用rest_total_hits_as_int=true
发送查询,则可以更改此值。