# Return total documents and source fields

**URL:** <https://discuss.elastic.co/t/return-total-documents-and-source-fields/101413>\
**Category:** Elasticsearch\
**Created:** [September 22, 2017, 2:39am UTC](https://discuss.elastic.co/t/return-total-documents-and-source-fields/101413 "2017-09-22T02:39:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sujituk](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@sujituk](https://discuss.elastic.co/u/sujituk)\
**Post date:** [September 22, 2017, 2:39am UTC](https://discuss.elastic.co/t/return-total-documents-and-source-fields/101413/1 "2017-09-22T02:39:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 20, 2017, 2:39am UTC](https://discuss.elastic.co/t/return-total-documents-and-source-fields/101413/2 "2017-10-20T02:39:53Z")

</div>

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