# Word count per document

**URL:** <https://discuss.elastic.co/t/word-count-per-document/17078>\
**Category:** Elasticsearch\
**Created:** [April 18, 2014, 11:52am UTC](https://discuss.elastic.co/t/word-count-per-document/17078 "2014-04-18T11:52:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aharon\_Twizer](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@Aharon\_Twizer](https://discuss.elastic.co/u/Aharon_Twizer)\
**Post date:** [April 18, 2014, 11:52am UTC](https://discuss.elastic.co/t/word-count-per-document/17078/1 "2014-04-18T11:52:53Z")

</div>

Hi,

I'm new to ElasticSearch.

What I want to do is to upload a few hundred documents and then look for  
words in those documents.

The most important part is to get the count of the each word per document.  
e.g. If I look for the word "boy", the answer I'll get is that it appears 3  
times in document A and 5 times in document B.

Can I do that with ElasticSearch?

Thanks in advanced!

Cheers,  
Aharon.

--  
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/f716d555-071f-44da-b868-6bc9ddd6455d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f716d555-071f-44da-b868-6bc9ddd6455d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Itamar\_Syn\_Hershko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itamar_syn_hershko/32/725_2.png) [@Itamar\_Syn\_Hershko](https://discuss.elastic.co/u/Itamar_Syn_Hershko)\
**Post date:** [April 18, 2014, 12:07pm UTC](https://discuss.elastic.co/t/word-count-per-document/17078/2 "2014-04-18T12:07:44Z")

</div>

Yes, take a look here:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

--

Itamar Syn-Hershko  
[http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
Freelance Developer & Consultant  
Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)

On Fri, Apr 18, 2014 at 2:52 PM, Aharon Twizer [aharon.twizer@gmail.com](mailto:aharon.twizer@gmail.com)wrote:

> Hi,
> 
> I'm new to Elasticsearch.
> 
> What I want to do is to upload a few hundred documents and then look for  
> words in those documents.
> 
> The most important part is to get the count of the each word per document.  
> e.g. If I look for the word "boy", the answer I'll get is that it appears 3  
> times in document A and 5 times in document B.
> 
> Can I do that with Elasticsearch?
> 
> Thanks in advanced!
> 
> Cheers,  
> Aharon.
> 
> --  
> 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/f716d555-071f-44da-b868-6bc9ddd6455d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f716d555-071f-44da-b868-6bc9ddd6455d%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/f716d555-071f-44da-b868-6bc9ddd6455d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/f716d555-071f-44da-b868-6bc9ddd6455d%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/CAHTr4Ztj0yDSS%2BAT8%3DM-DG7\_JrjfsrLuK725RzTPEF57s6wRPQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHTr4Ztj0yDSS%2BAT8%3DM-DG7_JrjfsrLuK725RzTPEF57s6wRPQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Aharon\_Twizer](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@Aharon\_Twizer](https://discuss.elastic.co/u/Aharon_Twizer)\
**Post date:** [April 18, 2014, 12:40pm UTC](https://discuss.elastic.co/t/word-count-per-document/17078/3 "2014-04-18T12:40:26Z")

</div>

Thanks Itamar.

But with the Term Vector I'll have to make a separate call for each  
document (I can have up to 20K documents).

I want to be able to make a single call with the word I'm looking for and  
to get the statistics for each document.

On Friday, April 18, 2014 2:52:53 PM UTC+3, Aharon Twizer wrote:

> Hi,
> 
> I'm new to Elasticsearch.
> 
> What I want to do is to upload a few hundred documents and then look for  
> words in those documents.
> 
> The most important part is to get the count of the each word per document.  
> e.g. If I look for the word "boy", the answer I'll get is that it appears 3  
> times in document A and 5 times in document B.
> 
> Can I do that with Elasticsearch?
> 
> Thanks in advanced!
> 
> Cheers,  
> Aharon.

--  
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/4e6e0ed5-3e3f-44a4-b11f-7f8efee2bbeb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4e6e0ed5-3e3f-44a4-b11f-7f8efee2bbeb%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Itamar\_Syn\_Hershko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itamar_syn_hershko/32/725_2.png) [@Itamar\_Syn\_Hershko](https://discuss.elastic.co/u/Itamar_Syn_Hershko)\
**Post date:** [April 18, 2014, 12:45pm UTC](https://discuss.elastic.co/t/word-count-per-document/17078/4 "2014-04-18T12:45:33Z")

</div>

You should be able to do this using the aggregations framework:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

The idea is that you bucket on document ID, and then on terms, then do a  
count

But I'm not sure it was designed to handle this scenario, where you have  
tens of thousands of buckets and then many unique terms in each bucket.  
Maybe someone from ES core can chime in on that.

--

Itamar Syn-Hershko  
[http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
Freelance Developer & Consultant  
Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)

On Fri, Apr 18, 2014 at 3:40 PM, Aharon Twizer [aharon.twizer@gmail.com](mailto:aharon.twizer@gmail.com)wrote:

> Thanks Itamar.
> 
> But with the Term Vector I'll have to make a separate call for each  
> document (I can have up to 20K documents).
> 
> I want to be able to make a single call with the word I'm looking for and  
> to get the statistics for each document.
> 
> On Friday, April 18, 2014 2:52:53 PM UTC+3, Aharon Twizer wrote:
> 
> > Hi,
> > 
> > I'm new to Elasticsearch.
> > 
> > What I want to do is to upload a few hundred documents and then look for  
> > words in those documents.
> > 
> > The most important part is to get the count of the each word per  
> > document. e.g. If I look for the word "boy", the answer I'll get is that it  
> > appears 3 times in document A and 5 times in document B.
> > 
> > Can I do that with Elasticsearch?
> > 
> > Thanks in advanced!
> > 
> > Cheers,  
> > Aharon.
> 
> --  
> 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/4e6e0ed5-3e3f-44a4-b11f-7f8efee2bbeb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4e6e0ed5-3e3f-44a4-b11f-7f8efee2bbeb%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/4e6e0ed5-3e3f-44a4-b11f-7f8efee2bbeb%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/4e6e0ed5-3e3f-44a4-b11f-7f8efee2bbeb%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/CAHTr4ZtQiwBa17exGbhoiGR%2B3-hvYMK4\_3ueci1V\_Lu7TS23WA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZtQiwBa17exGbhoiGR%2B3-hvYMK4_3ueci1V_Lu7TS23WA%40mail.gmail.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, 1:35am UTC](https://discuss.elastic.co/t/word-count-per-document/17078/5 "2017-07-06T01:35:03Z")

</div>


