对于我的用例,我想通过查询搜索并获得所有结果。我使用滚动来获得所有结果。
https://ip:p/key/_search?scroll=2m
(with the very complex query in json here .... i suppose)
然后我会使用滚动来获得结果,直到它出错。
https://ip:p/_search/scroll
{
"scroll" : "2m",
"scroll_id" : "DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAA5NAWLU51eGVMN29RajJRMmlubHV1eFdLdw=="
}
我想知道在得到所有结果之前,我需要调用多少个总结果,或者多少个消耗滚动,以估计进度条或剩余时间。
您可以使用track_total_hits=true。它将返回文档的总数。
GET index18/_search?scroll=1m&track_total_hits=true
{
"size": 2,
"query": {
"match_all": {}
}
}
结果:
"hits" : {
"total" : {
"value" : 4, --> note
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "index18",
"_type" : "_doc",
"_id" : "iSCe6nEB8J88APx3YBGn",
"_score" : 1.0,
"_source" : {
"field1" : "test",
"field2" : "test"
}
},
{
"_index" : "index18",
"_type" : "_doc",
"_id" : "iiCe6nEB8J88APx3ghF-",
"_score" : 1.0,
"_source" : {
"field1" : "test",
"field2" : "abc"
}
}
]
}
每个请求要求2条记录,记录总数为4条。因此,在第一个请求中,50%的数据将被提取