# Total number of documents be included in each query

**URL:** <https://discuss.elastic.co/t/total-number-of-documents-be-included-in-each-query/19633>\
**Category:** Elasticsearch\
**Created:** [September 4, 2014, 9:01pm UTC](https://discuss.elastic.co/t/total-number-of-documents-be-included-in-each-query/19633 "2014-09-04T21:01:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kazoompa\_3](https://avatars.discourse-cdn.com/v4/letter/k/958977/32.png) [@kazoompa\_3](https://discuss.elastic.co/u/kazoompa_3)\
**Post date:** [September 4, 2014, 9:01pm UTC](https://discuss.elastic.co/t/total-number-of-documents-be-included-in-each-query/19633/1 "2014-09-04T21:01:21Z")

</div>

> Hi,

I would like to know whether I can perform a query and get not only the  
total hits but also the total document counts.

Here is an example of one of my queries:

{  
"from" : 0,  
"size" : 30,  
"query" : {  
"filtered" : {  
"query" : {  
"match\_all" : { }  
},  
"filter" : {  
"bool" : {  
"must" : {  
"terms" : {  
"valueType" : ["decimal"]  
}  
}  
}  
}  
}  
},  
"aggregations" : {  
"variableType" : {  
"terms" : {  
"field" : "variableType",  
"order" : {  
"\_term" : "asc"  
}  
}  
}  
}  
}

And a part of my sample response:

{  
"took" : 7,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 285,  
"max\_score" : 1.0,  
"hits" : [{...}]  
}

I would love to include the total documents count as well, as if I had done  
a _match\_all()_ query only.

Thanks a lot.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c11848bb-7767-42da-a4c3-60892b766116%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c11848bb-7767-42da-a4c3-60892b766116%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 4, 2014, 9:09pm UTC](https://discuss.elastic.co/t/total-number-of-documents-be-included-in-each-query/19633/2 "2014-09-04T21:09:20Z")

</div>

You could try [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-multi-search.html)

Or this: [Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html)

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

> Le 4 sept. 2014 à 23:01, kazoompa [rhaeri@p3g.org](mailto:rhaeri@p3g.org) a écrit :

> Hi,  
> I would like to know whether I can perform a query and get not only the total hits but also the total document counts.

Here is an example of one of my queries:

{  
"from" : 0,  
"size" : 30,  
"query" : {  
"filtered" : {  
"query" : {  
"match\_all" : { }  
},  
"filter" : {  
"bool" : {  
"must" : {  
"terms" : {  
"valueType" : ["decimal"]  
}  
}  
}  
}  
}  
},  
"aggregations" : {  
"variableType" : {  
"terms" : {  
"field" : "variableType",  
"order" : {  
"\_term" : "asc"  
}  
}  
}  
}  
}

And a part of my sample response:

{  
"took" : 7,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 285,  
"max\_score" : 1.0,  
"hits" : [{...}]  
}

I would love to include the total documents count as well, as if I had done a match\_all() query only.

## Thanks a lot.

You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c11848bb-7767-42da-a4c3-60892b766116%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c11848bb-7767-42da-a4c3-60892b766116%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/E01FBBCB-2918-4373-BD24-82CA26EF92F0%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/E01FBBCB-2918-4373-BD24-82CA26EF92F0%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![kazoompa\_3](https://avatars.discourse-cdn.com/v4/letter/k/958977/32.png) [@kazoompa\_3](https://discuss.elastic.co/u/kazoompa_3)\
**Post date:** [September 5, 2014, 1:41pm UTC](https://discuss.elastic.co/t/total-number-of-documents-be-included-in-each-query/19633/3 "2014-09-05T13:41:49Z")

</div>

Fantastic, Thanks David.

BTW, I have to thank you for your video presentation in French, it really  
helped me a lot to understand the basics od ES two years ago.

Cheers.

On Thursday, September 4, 2014 5:09:35 PM UTC-4, David Pilato wrote:

> You could try  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-multi-search.html)
> 
> Or this:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html)
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 4 sept. 2014 à 23:01, kazoompa \<[rha...@p3g.org](mailto:rha...@p3g.org) \<javascript:\>\> a écrit :
> 
> Hi,
> 
> I would like to know whether I can perform a query and get not only the  
> total hits but also the total document counts.
> 
> Here is an example of one of my queries:
> 
> {  
> "from" : 0,  
> "size" : 30,  
> "query" : {  
> "filtered" : {  
> "query" : {  
> "match\_all" : { }  
> },  
> "filter" : {  
> "bool" : {  
> "must" : {  
> "terms" : {  
> "valueType" : ["decimal"]  
> }  
> }  
> }  
> }  
> }  
> },  
> "aggregations" : {  
> "variableType" : {  
> "terms" : {  
> "field" : "variableType",  
> "order" : {  
> "\_term" : "asc"  
> }  
> }  
> }  
> }  
> }
> 
> And a part of my sample response:
> 
> {  
> "took" : 7,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 285,  
> "max\_score" : 1.0,  
> "hits" : [{...}]  
> }
> 
> I would love to include the total documents count as well, as if I had  
> done a _match\_all()_ query only.
> 
> Thanks a lot.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/c11848bb-7767-42da-a4c3-60892b766116%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c11848bb-7767-42da-a4c3-60892b766116%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/c11848bb-7767-42da-a4c3-60892b766116%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c11848bb-7767-42da-a4c3-60892b766116%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9964220a-0c74-4164-a49d-b13e0fc8a3f7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9964220a-0c74-4164-a49d-b13e0fc8a3f7%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 5, 2014, 1:49pm UTC](https://discuss.elastic.co/t/total-number-of-documents-be-included-in-each-query/19633/4 "2014-09-05T13:49:52Z")

</div>

Cool! Lot of things have changed since though! 🙂

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 5 sept. 2014 à 15:41, kazoompa [rhaeri@p3g.org](mailto:rhaeri@p3g.org) a écrit :

Fantastic, Thanks David.

BTW, I have to thank you for your video presentation in French, it really helped me a lot to understand the basics od ES two years ago.

Cheers.

> On Thursday, September 4, 2014 5:09:35 PM UTC-4, David Pilato wrote:  
> You could try [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-multi-search.html)
> 
> Or this: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html)
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> > Le 4 sept. 2014 à 23:01, kazoompa [rha...@p3g.org](mailto:rha...@p3g.org) a écrit :
> 
> > Hi,  
> > I would like to know whether I can perform a query and get not only the total hits but also the total document counts.
> 
> Here is an example of one of my queries:
> 
> {  
> "from" : 0,  
> "size" : 30,  
> "query" : {  
> "filtered" : {  
> "query" : {  
> "match\_all" : { }  
> },  
> "filter" : {  
> "bool" : {  
> "must" : {  
> "terms" : {  
> "valueType" : ["decimal"]  
> }  
> }  
> }  
> }  
> }  
> },  
> "aggregations" : {  
> "variableType" : {  
> "terms" : {  
> "field" : "variableType",  
> "order" : {  
> "\_term" : "asc"  
> }  
> }  
> }  
> }  
> }
> 
> And a part of my sample response:
> 
> {  
> "took" : 7,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 285,  
> "max\_score" : 1.0,  
> "hits" : [{...}]  
> }
> 
> I would love to include the total documents count as well, as if I had done a match\_all() query only.
> 
> ## Thanks a lot.
> 
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c11848bb-7767-42da-a4c3-60892b766116%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c11848bb-7767-42da-a4c3-60892b766116%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9964220a-0c74-4164-a49d-b13e0fc8a3f7%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9964220a-0c74-4164-a49d-b13e0fc8a3f7%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/FB6AB667-5722-40D5-91FD-73FD65775011%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/FB6AB667-5722-40D5-91FD-73FD65775011%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 1:04am UTC](https://discuss.elastic.co/t/total-number-of-documents-be-included-in-each-query/19633/5 "2017-07-06T01:04:06Z")

</div>


