Reputation: 5546
For my use case, I would like to search and get all result with a query. I use scroll to get all result.
https://ip:p/key/_search?scroll=2m
(with the very complex query in json here .... i suppose)
Then I would consume scroll to get result until it error.
https://ip:p/_search/scroll
{
"scroll" : "2m",
"scroll_id" : "DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAA5NAWLU51eGVMN29RajJRMmlubHV1eFdLdw=="
}
I would like to know how many total result, or how many consume scroll I would need to call until I get all result, to estimate the progress bar or remaining time.
Upvotes: 0
Views: 509
Reputation: 9099
You can use track_total_hits=true. It will return total number of documents.
GET index18/_search?scroll=1m&track_total_hits=true
{
"size": 2,
"query": {
"match_all": {}
}
}
Result:
"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"
}
}
]
}
Each request is asking for 2 records and total number of records are 4 . So in first request 50% data will be fetched
Upvotes: 1