# Get Number of Hits in a larger Text foreach search Term

**URL:** https://discuss.elastic.co/t/get-number-of-hits-in-a-larger-text-foreach-search-term/9352
**Category:** Elasticsearch
**Created:** [October 14, 2012, 10:50am UTC](https://discuss.elastic.co/t/get-number-of-hits-in-a-larger-text-foreach-search-term/9352 "2012-10-14T10:50:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![florigee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/florigee/32/2683_2.png) [@florigee](https://discuss.elastic.co/u/florigee)
#### Post date: [October 14, 2012, 10:50am UTC](https://discuss.elastic.co/t/get-number-of-hits-in-a-larger-text-foreach-search-term/9352/1 "2012-10-14T10:50:12Z")

</div>

Hello,

I am now in my third day of research on that topic. I am using ElasticSearch with Tire in my Rails app. The most important search functionality is where users can search in larger Texts (CVs of People), if the text has the right keywords in it. e.g. "Java AND Oracle" will show all texts having keyword Java and keyword Oracle in it. Everthing works fine so far.  
But I am requested if the search results can return the number of hits in a document. So maybe like first result (5 times Java, 3 time Oracle), second result (7 times java, 1 time oracle), ...

Is there a possibility to display the number of matching words in a result? I couldn't find anything in the docs and even in this forum. I am sorry, when I just didn't see it. Please help!

Thank you a lot  
Florigee

---

<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: [October 16, 2012, 3:13pm UTC](https://discuss.elastic.co/t/get-number-of-hits-in-a-larger-text-foreach-search-term/9352/2 "2012-10-16T15:13:41Z")

</div>

Elasticsearch does not easily provide the number of matching words in a  
result. You can turn on debugging for each query and parse the Explain  
object, which should have a list of all the term frequencies matched.

It might sound like it would be more work to parse the explain object  
instead of just looking at the content return yourself, but the term  
frequencies in explain are after analysis, so you get a count of the query  
term after synonyms, stemmers, filtering, etc...

I am not a JSON user, does JSON having something like XPath? It would be  
almost trivial parsing the explain result with something like XPath.

Cheers,

Ivan

On Sun, Oct 14, 2012 at 3:50 AM, florigee [florian.goerlitz@gmail.com](mailto:florian.goerlitz@gmail.com)wrote:

> Hello,
> 
> I am now in my third day of research on that topic. I am using  
> Elasticsearch  
> with Tire in my Rails app. The most important search functionality is where  
> users can search in larger Texts (CVs of People), if the text has the right  
> keywords in it. e.g. "Java AND Oracle" will show all texts having keyword  
> Java and keyword Oracle in it. Everthing works fine so far.  
> But I am requested if the search results can return the number of hits in a  
> document. So maybe like first result (5 times Java, 3 time Oracle), second  
> result (7 times java, 1 time oracle), ...
> 
> Is there a possibility to display the number of matching words in a result?  
> I couldn't find anything in the docs and even in this forum. I am sorry,  
> when I just didn't see it. Please help!
> 
> Thank you a lot  
> Florigee
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Get-Number-of-Hits-in-a-larger-Text-foreach-search-Term-tp4023952.html](http://elasticsearch-users.115913.n3.nabble.com/Get-Number-of-Hits-in-a-larger-Text-foreach-search-Term-tp4023952.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --

--

---

<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, 3:08am UTC](https://discuss.elastic.co/t/get-number-of-hits-in-a-larger-text-foreach-search-term/9352/3 "2017-07-06T03:08:30Z")

</div>


