# Does anyone know of a way to get elasticsearch to return a word count?

**URL:** https://discuss.elastic.co/t/does-anyone-know-of-a-way-to-get-elasticsearch-to-return-a-word-count/13913
**Category:** Elasticsearch
**Created:** [October 10, 2013, 9:52pm UTC](https://discuss.elastic.co/t/does-anyone-know-of-a-way-to-get-elasticsearch-to-return-a-word-count/13913 "2013-10-10T21:52:04Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [October 10, 2013, 9:52pm UTC](https://discuss.elastic.co/t/does-anyone-know-of-a-way-to-get-elasticsearch-to-return-a-word-count/13913/1 "2013-10-10T21:52:04Z")

</div>

It looks like my user interface returns a word count and it was sneakily  
implemented by faulting text in from the database and running  
str\_word\_count on it. I'd rather have elasticsearch calculate the number  
of words in my text so I don't have to load to show search results. Does  
anyone know a good way to do that? I assume it'd make more sense to store  
the word count on index into another field and just fetch it.

Nik

--  
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: ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)
#### Post date: [October 11, 2013, 9:17pm UTC](https://discuss.elastic.co/t/does-anyone-know-of-a-way-to-get-elasticsearch-to-return-a-word-count/13913/2 "2013-10-11T21:17:15Z")

</div>

can you go a bit more into detail here? are you asking for the frequency of  
a word across the entire index or within a document? How do you need to  
select words?

simon

On Thursday, October 10, 2013 11:52:04 PM UTC+2, Nikolas Everett wrote:

> It looks like my user interface returns a word count and it was sneakily  
> implemented by faulting text in from the database and running  
> str\_word\_count on it. I'd rather have elasticsearch calculate the number  
> of words in my text so I don't have to load to show search results. Does  
> anyone know a good way to do that? I assume it'd make more sense to store  
> the word count on index into another field and just fetch it.
> 
> Nik

--  
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: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [October 11, 2013, 9:25pm UTC](https://discuss.elastic.co/t/does-anyone-know-of-a-way-to-get-elasticsearch-to-return-a-word-count/13913/3 "2013-10-11T21:25:54Z")

</div>

Just the number of terms in some field in the document. It is is a field I both query and highlight. I'd be happy with something approximate. I saw today I might be able to do a bit of math on the field norm to get it.

Sent from my iPhone

> On Oct 11, 2013, at 5:17 PM, simonw [simon.willnauer@elasticsearch.com](mailto:simon.willnauer@elasticsearch.com) wrote:
> 
> can you go a bit more into detail here? are you asking for the frequency of a word across the entire index or within a document? How do you need to select words?
> 
> simon
> 
> > On Thursday, October 10, 2013 11:52:04 PM UTC+2, Nikolas Everett wrote:  
> > It looks like my user interface returns a word count and it was sneakily implemented by faulting text in from the database and running str\_word\_count on it. I'd rather have elasticsearch calculate the number of words in my text so I don't have to load to show search results. Does anyone know a good way to do that? I assume it'd make more sense to store the word count on index into another field and just fetch it.
> > 
> > Nik
> 
> --  
> 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: ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)
#### Post date: [October 13, 2013, 5:14pm UTC](https://discuss.elastic.co/t/does-anyone-know-of-a-way-to-get-elasticsearch-to-return-a-word-count/13913/4 "2013-10-13T17:14:58Z")

</div>

the field norm might help but it's hard to access and it's a 8bit float  
value that includes the boosts so it might be quite lossy? What you could  
do in master is using a TermVector and consume the field in the client  
since it contains all terms for a field in a document.

On Friday, October 11, 2013 11:25:54 PM UTC+2, Nikolas Everett wrote:

> Just the number of terms in some field in the document. It is is a field I  
> both query and highlight. I'd be happy with something approximate. I saw  
> today I might be able to do a bit of math on the field norm to get it.
> 
> Sent from my iPhone
> 
> On Oct 11, 2013, at 5:17 PM, simonw \<[simon.w...@elasticsearch.com](mailto:simon.w...@elasticsearch.com)\<javascript:\>\>  
> wrote:
> 
> can you go a bit more into detail here? are you asking for the frequency  
> of a word across the entire index or within a document? How do you need to  
> select words?
> 
> simon
> 
> On Thursday, October 10, 2013 11:52:04 PM UTC+2, Nikolas Everett wrote:
> 
> > It looks like my user interface returns a word count and it was sneakily  
> > implemented by faulting text in from the database and running  
> > str\_word\_count on it. I'd rather have elasticsearch calculate the number  
> > of words in my text so I don't have to load to show search results. Does  
> > anyone know a good way to do that? I assume it'd make more sense to store  
> > the word count on index into another field and just fetch it.
> > 
> > Nik
> 
> --  
> 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:\>.  
> 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:12am UTC](https://discuss.elastic.co/t/does-anyone-know-of-a-way-to-get-elasticsearch-to-return-a-word-count/13913/5 "2017-07-06T02:12:43Z")

</div>


