# How to get total term frequency within a document

**URL:** <https://discuss.elastic.co/t/how-to-get-total-term-frequency-within-a-document/20707>\
**Category:** Elasticsearch\
**Created:** [November 12, 2014, 2:19pm UTC](https://discuss.elastic.co/t/how-to-get-total-term-frequency-within-a-document/20707 "2014-11-12T14:19:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anas\_nain](https://avatars.discourse-cdn.com/v4/letter/a/74df32/32.png) [@anas\_nain](https://discuss.elastic.co/u/anas_nain)\
**Post date:** [November 12, 2014, 2:19pm UTC](https://discuss.elastic.co/t/how-to-get-total-term-frequency-within-a-document/20707/1 "2014-11-12T14:19:11Z")

</div>

i am writing java code for getting total term frequency(number of times a  
term occured within a document).  
please help me to write this.

here is the document that i inserted into elastic search index.  
"resp\_aaa\_error":[  
{"edi\_location":"Payer","error\_code":"45","followup\_action\_code":"R"},  
{"edi\_location":"Payer  
ID","error\_code":"45","followup\_action\_code":"R"},  
{"edi\_location":"Dependent  
ID","error\_code":"45","followup\_action\_code":"R"},  
{"edi\_location":"Subscriber  
ID","error\_code":"45","followup\_action\_code":"R"}  
]  
but when i count how many no of times error\_code is equal to 45, it  
returns 1.  
but i want it to return 4 as it is 4 times in my document.

please help me. it's kind of urgent.

--  
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/c7606ef4-7876-468e-90ac-2905cfef7eb8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c7606ef4-7876-468e-90ac-2905cfef7eb8%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:50am UTC](https://discuss.elastic.co/t/how-to-get-total-term-frequency-within-a-document/20707/2 "2017-07-06T00:50:30Z")

</div>


