Return total documents and source fields

My requirement is in the area of pagination. Based on my query, I need to return the total number (let's say N) of documents and return specific fields (mostly source) for result set 1 of N (total), result set 2 of N (total) etc.

I was able to write 2 separate queries to get the information I needed:

Query1:
GET /my_index/_search?filter_path=hits.hits._source
{
"query": {
"match": {
"history": "test"
}
}
, "sort": [
{
"_score": {
"order": "desc"
}
}
]
, "size": 10
}
Query2:
GET /my_index/_search?filter_path=hits.total
{
"query": {
"match": {
"history": "test"
}
}
, "sort": [
{
"_score": {
"order": "desc"
}
}
]
, "size": 10
}

How can I write a single query that can give me this in a single call to ES? Multisearch could be an option, but want to check with the pro's before I venture there.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.