# Number of results to equal number of times query appears in document

**URL:** https://discuss.elastic.co/t/number-of-results-to-equal-number-of-times-query-appears-in-document/11512
**Category:** Elasticsearch
**Created:** [April 9, 2013, 5:29pm UTC](https://discuss.elastic.co/t/number-of-results-to-equal-number-of-times-query-appears-in-document/11512 "2013-04-09T17:29:37Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![irfan\_mir](https://avatars.discourse-cdn.com/v4/letter/i/278dde/32.png) [@irfan\_mir](https://discuss.elastic.co/u/irfan_mir)
#### Post date: [April 9, 2013, 5:29pm UTC](https://discuss.elastic.co/t/number-of-results-to-equal-number-of-times-query-appears-in-document/11512/1 "2013-04-09T17:29:37Z")

</div>

Hello,  
I'm using Elastica, a PHP implementation of Elastic Search, and I was told  
something could not be done in Elastica because it can not be done with  
Elastic Search and I am just checking if it really can not be done with  
Elastic Search.

Right now, if a query is found in a document that counts as one result. If  
the query is found in another document that counts as one result.  
Is there a way I can get the results to match the number of times a query  
is in the document instead of one result per document.  
Like a browser's ctrl / cmd + f functionality returns 3 if the query is  
found 3 times in a document.

Please let me know if this is possible and how.

I would greatly appreciate any and all help!

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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [April 9, 2013, 11:50pm UTC](https://discuss.elastic.co/t/number-of-results-to-equal-number-of-times-query-appears-in-document/11512/2 "2013-04-09T23:50:45Z")

</div>

You could potentially enabled explain on the query, then for each document  
you can extract the term frequency of the term from the explain object.  
Term frequencies need to be enabled on the field. You might encounter  
issues depending on how the text is analyzed, especially if you apply  
stemming.

--  
Ivan

On Tue, Apr 9, 2013 at 10:29 AM, irfan mir [theirf@gmail.com](mailto:theirf@gmail.com) wrote:

> Hello,  
> I'm using Elastica, a PHP implementation of Elastic Search, and I was told  
> something could not be done in Elastica because it can not be done with  
> Elastic Search and I am just checking if it really can not be done with  
> Elastic Search.
> 
> Right now, if a query is found in a document that counts as one result. If  
> the query is found in another document that counts as one result.  
> Is there a way I can get the results to match the number of times a query  
> is in the document instead of one result per document.  
> Like a browser's ctrl / cmd + f functionality returns 3 if the query is  
> found 3 times in a document.
> 
> Please let me know if this is possible and how.
> 
> I would greatly appreciate any and all help!
> 
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:41am UTC](https://discuss.elastic.co/t/number-of-results-to-equal-number-of-times-query-appears-in-document/11512/3 "2017-07-06T02:41:55Z")

</div>


