# Getting query count for individula fields in multi match query

**URL:** <https://discuss.elastic.co/t/getting-query-count-for-individula-fields-in-multi-match-query/21975>\
**Category:** Elasticsearch\
**Created:** [February 4, 2015, 1:14pm UTC](https://discuss.elastic.co/t/getting-query-count-for-individula-fields-in-multi-match-query/21975 "2015-02-04T13:14:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anand\_kumar](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Anand\_kumar](https://discuss.elastic.co/u/Anand_kumar)\
**Post date:** [February 4, 2015, 1:14pm UTC](https://discuss.elastic.co/t/getting-query-count-for-individula-fields-in-multi-match-query/21975/1 "2015-02-04T13:14:29Z")

</div>

Hi all,

```
    Is it possible to get the query count per field, while querying via 

```

multi match query?

```
    {
         "multi_match" : {
              "query": "this is a test", 
              "fields": ["subject", "message"] 
          }
    }

   In above query, can i able to get the the no of matches from the 

```

subject field and message field, is there any other way to make it?

```
   Any suggestion would be helpful.

   Thanks in advance.

```

--  
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/13ddfd94-ed9b-4fda-a768-fcd21c14fc37%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/13ddfd94-ed9b-4fda-a768-fcd21c14fc37%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [February 4, 2015, 1:27pm UTC](https://discuss.elastic.co/t/getting-query-count-for-individula-fields-in-multi-match-query/21975/2 "2015-02-04T13:27:24Z")

</div>

Hi ,

There is a way to do it.  
You need to use the filter aggregation  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html)  
.

Keep 2 filters one for match on subject field and other on message field.

{  
"query": {  
"multi\_match": {  
"query": "this is a test",  
"fields": [  
"subject",  
"message"  
]  
}  
},  
"aggs": {  
"messageField": {  
"filter": {  
"query": {  
"match": {  
"message": "this is a test"  
}  
}  
}  
},  
"subjectField": {  
"filter": {  
"query": {  
"match": {  
"subject": "this is a test"  
}  
}  
}  
}  
}  
}

Thanks  
Vineeth Mohan,  
Elasticsearch consultant,  
[qbox.io](http://qbox.io) ( Elasticsearch service provider [http://qbox.io](http://qbox.io))

On Wed, Feb 4, 2015 at 6:44 PM, Anand kumar [anandv1000@gmail.com](mailto:anandv1000@gmail.com) wrote:

> Hi all,
> 
> ```
> Is it possible to get the query count per field, while querying
> 
> ```
> 
> via multi match query?
> 
> ```
> {
> "multi_match" : {
> "query": "this is a test",
> "fields": ["subject", "message"]
> }
> }
> 
> In above query, can i able to get the the no of matches from the
> 
> ```
> 
> subject field and message field, is there any other way to make it?
> 
> ```
> Any suggestion would be helpful.
> 
> Thanks in advance.
> 
> ```
> 
> --  
> 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/13ddfd94-ed9b-4fda-a768-fcd21c14fc37%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/13ddfd94-ed9b-4fda-a768-fcd21c14fc37%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/13ddfd94-ed9b-4fda-a768-fcd21c14fc37%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/13ddfd94-ed9b-4fda-a768-fcd21c14fc37%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/CAGdPd5ncEk9w%2ByFObk%3DHcCZpftBFdndLte9YNt7hDMnZuea36A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5ncEk9w%2ByFObk%3DHcCZpftBFdndLte9YNt7hDMnZuea36A%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Anand\_kumar](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@Anand\_kumar](https://discuss.elastic.co/u/Anand_kumar)\
**Post date:** [February 5, 2015, 12:48pm UTC](https://discuss.elastic.co/t/getting-query-count-for-individula-fields-in-multi-match-query/21975/3 "2015-02-05T12:48:57Z")

</div>

Hi Vineeth,

First of all, thank you for your suggestion.

BTW as you suggested, I can only able to get the no of matched documents.  
But what I need is the no of matches of the querystring in each field.

I can also make termquery for each field individually, as it would result  
in time consumption I dont want to that.

Could you help me out?

Thanks again.

Regards,  
Anand

On Wednesday, 4 February 2015 18:58:35 UTC+5:30, vineeth mohan wrote:

> Hi ,
> 
> There is a way to do it.  
> You need to use the filter aggregation  
> [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html)  
> .
> 
> Keep 2 filters one for match on subject field and other on message field.
> 
> {  
> "query": {  
> "multi\_match": {  
> "query": "this is a test",  
> "fields": [  
> "subject",  
> "message"  
> ]  
> }  
> },  
> "aggs": {  
> "messageField": {  
> "filter": {  
> "query": {  
> "match": {  
> "message": "this is a test"  
> }  
> }  
> }  
> },  
> "subjectField": {  
> "filter": {  
> "query": {  
> "match": {  
> "subject": "this is a test"  
> }  
> }  
> }  
> }  
> }  
> }
> 
> Thanks  
> Vineeth Mohan,  
> Elasticsearch consultant,  
> [qbox.io](http://qbox.io) ( Elasticsearch service provider [http://qbox.io](http://qbox.io))
> 
> On Wed, Feb 4, 2015 at 6:44 PM, Anand kumar \<[anand...@gmail.com](mailto:anand...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Hi all,
> > 
> > ```
> > Is it possible to get the query count per field, while querying 
> > 
> > ```
> > 
> > via multi match query?
> > 
> > ```
> > {
> > "multi_match" : {
> > "query": "this is a test", 
> > "fields": ["subject", "message"] 
> > }
> > }
> > 
> > In above query, can i able to get the the no of matches from the 
> > 
> > ```
> > 
> > subject field and message field, is there any other way to make it?
> > 
> > ```
> > Any suggestion would be helpful.
> > 
> > Thanks in advance.
> > 
> > ```
> > 
> > --  
> > 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/13ddfd94-ed9b-4fda-a768-fcd21c14fc37%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/13ddfd94-ed9b-4fda-a768-fcd21c14fc37%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/13ddfd94-ed9b-4fda-a768-fcd21c14fc37%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/13ddfd94-ed9b-4fda-a768-fcd21c14fc37%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/e2fa7b1b-7720-4e94-885a-12f62b0cd0f8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e2fa7b1b-7720-4e94-885a-12f62b0cd0f8%40googlegroups.com).  
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, 12:34am UTC](https://discuss.elastic.co/t/getting-query-count-for-individula-fields-in-multi-match-query/21975/4 "2017-07-06T00:34:47Z")

</div>


