# How to get count of returned data in match query?

**URL:** https://discuss.elastic.co/t/how-to-get-count-of-returned-data-in-match-query/193618
**Category:** Elasticsearch
**Created:** [August 2, 2019, 10:56pm UTC](https://discuss.elastic.co/t/how-to-get-count-of-returned-data-in-match-query/193618 "2019-08-02T22:56:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Bidzina\_Goginashvili](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bidzina_goginashvili/32/51114_2.png) [@Bidzina\_Goginashvili](https://discuss.elastic.co/u/Bidzina_Goginashvili)
#### Post date: [August 2, 2019, 10:56pm UTC](https://discuss.elastic.co/t/how-to-get-count-of-returned-data-in-match-query/193618/1 "2019-08-02T22:56:46Z")

</div>

> GET index/\_search  
> {  
> "query": {"terms": {  
> "id": ["114383"]  
> }}  
> get the count of this matched data  
> }

and also get the count of this

> GET products/\_search  
> {  
> "query": {  
> "match" : {  
> "inStorage": "true"  
> }  
> }  
> //get count of this data  
> }

---

<div class="post-metadata">

### Author: ![wangqinghuan](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wangqinghuan](https://discuss.elastic.co/u/wangqinghuan)
#### Post date: [August 3, 2019, 7:59am UTC](https://discuss.elastic.co/t/how-to-get-count-of-returned-data-in-match-query/193618/2 "2019-08-03T07:59:11Z")

</div>

1. Using search method as your code and extract count from field['hits']['total'] in response.
2. Using count method directly, which would return the count of your matched documents.  
The count method is more faster if you only care the count of matched data because count method does not need to fetch result and rank by score. Another, setting the search size to 0 in search method can also decrease the overhead of fetching and scoring, which is similar to count method.

---

<div class="post-metadata">

### Author: ![Bidzina\_Goginashvili](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bidzina_goginashvili/32/51114_2.png) [@Bidzina\_Goginashvili](https://discuss.elastic.co/u/Bidzina_Goginashvili)
#### Post date: [August 3, 2019, 3:09pm UTC](https://discuss.elastic.co/t/how-to-get-count-of-returned-data-in-match-query/193618/3 "2019-08-03T15:09:59Z")

</div>

GET /products/\_count  
{  
"query": {  
"bool": {  
"filter": [  
{  
"terms": {  
"categories.id": ["9"]  
}  
},  
{  
"terms": {  
"manufacturers.id": ["216"]  
}  
},  
{  
"terms": {  
"options.id": ["845"]  
}  
},  
{  
"term": {  
"inStorage.": "true"  
}  
}  
]  
}  
}  
}  
thank you but is it possible to filter terms with term?

---

<div class="post-metadata">

### Author: ![wangqinghuan](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wangqinghuan](https://discuss.elastic.co/u/wangqinghuan)
#### Post date: [August 4, 2019, 7:29am UTC](https://discuss.elastic.co/t/how-to-get-count-of-returned-data-in-match-query/193618/4 "2019-08-04T07:29:53Z")

</div>

> [@Bidzina\_Goginashvili](#):
>
> {  
> "query": {  
> "bool": {  
> "filter": [  
> {  
> "terms": {  
> "categories.id": ["9"]  
> }  
> },

yes.

---

<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: [September 1, 2019, 7:29am UTC](https://discuss.elastic.co/t/how-to-get-count-of-returned-data-in-match-query/193618/5 "2019-09-01T07:29:54Z")

</div>

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