# Sum of total term frequency in ONE document

**URL:** <https://discuss.elastic.co/t/sum-of-total-term-frequency-in-one-document/21289>\
**Category:** Elasticsearch\
**Created:** [December 17, 2014, 9:27am UTC](https://discuss.elastic.co/t/sum-of-total-term-frequency-in-one-document/21289 "2014-12-17T09:27:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![valerij\_vasilcenko](https://avatars.discourse-cdn.com/v4/letter/v/ba9def/32.png) [@valerij\_vasilcenko](https://discuss.elastic.co/u/valerij_vasilcenko)\
**Post date:** [December 17, 2014, 9:27am UTC](https://discuss.elastic.co/t/sum-of-total-term-frequency-in-one-document/21289/1 "2014-12-17T09:27:54Z")

</div>

I need sumttf of ONE document in a field. However I can get sumttf of all  
documents only...  
I need to be able to access the variable in script like  
\_index['field'].sumttf() of that particular document. This is what I've got  
so far.

Mapping:

```
{"document2" : {
  "mappings" : {
    "document2" : {
      "_all" : {
        "enabled" : false
      },
      "properties" : {
        "content" : {
          "type" : "string",
          "term_vector" : "yes",
          "fields" : {
            "with_shingles" : {
              "type" : "string",
              "analyzer" : "my_shingle_analyzer"
            }
          }
        },
        ...

```

Term vector:

```
"_index" : "document2",
"_type" : "document2",
"_id" : "709718",
"_version" : 1,
"term_vectors" : {
    "content" : {
      "field_statistics" : {
        "sum_doc_freq" : 60676474,
        "doc_count" : 198373,
        "sum_ttf" : 224960172
      },
      terms" : {
        "0" : {
          "term_freq" : 8
        },
        "0.5" : {
          "term_freq" : 1
        },
        "003a0e45ea07a" : {
          "term_freq" : 1
        },
        "005" : {
          "term_freq" : 1
        },
        "0081989" : {
          "term_freq" : 1
        },
        "01" : {
          "term_freq" : 1
        },
        "01.08.2002" : {
          "term_freq" : 1
        },
        ...

```

--  
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/b9afb2c4-bde4-4c60-b026-aa2c24227c03%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b9afb2c4-bde4-4c60-b026-aa2c24227c03%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [December 20, 2014, 8:33pm UTC](https://discuss.elastic.co/t/sum-of-total-term-frequency-in-one-document/21289/2 "2014-12-20T20:33:21Z")

</div>

Hi ,

Why dont you use script fields to access this value -

> **[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.

Thanks  
Vineeth

On Wed, Dec 17, 2014 at 2:57 PM, [valerij.vasilcenko@googlemail.com](mailto:valerij.vasilcenko@googlemail.com) wrote:

> I need sumttf of ONE document in a field. However I can get sumttf of all  
> documents only...  
> I need to be able to access the variable in script like  
> \_index['field'].sumttf() of that particular document. This is what I've got  
> so far.
> 
> Mapping:
> 
> ```
> {"document2" : {
> "mappings" : {
> "document2" : {
> "_all" : {
> "enabled" : false
> },
> "properties" : {
> "content" : {
> "type" : "string",
> "term_vector" : "yes",
> "fields" : {
> "with_shingles" : {
> "type" : "string",
> "analyzer" : "my_shingle_analyzer"
> }
> }
> },
> ...
> 
> ```
> 
> Term vector:
> 
> ```
> "_index" : "document2",
> "_type" : "document2",
> "_id" : "709718",
> "_version" : 1,
> "term_vectors" : {
> "content" : {
> "field_statistics" : {
> "sum_doc_freq" : 60676474,
> "doc_count" : 198373,
> "sum_ttf" : 224960172
> },
> terms" : {
> "0" : {
> "term_freq" : 8
> },
> "0.5" : {
> "term_freq" : 1
> },
> "003a0e45ea07a" : {
> "term_freq" : 1
> },
> "005" : {
> "term_freq" : 1
> },
> "0081989" : {
> "term_freq" : 1
> },
> "01" : {
> "term_freq" : 1
> },
> "01.08.2002" : {
> "term_freq" : 1
> },
> ...
> 
> ```
> 
> --  
> 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/b9afb2c4-bde4-4c60-b026-aa2c24227c03%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b9afb2c4-bde4-4c60-b026-aa2c24227c03%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/b9afb2c4-bde4-4c60-b026-aa2c24227c03%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/b9afb2c4-bde4-4c60-b026-aa2c24227c03%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/CAGdPd5nx2PZbAp%2BL732sShWY82Bhthurs8nPL\_Ck3gG13uPhZQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nx2PZbAp%2BL732sShWY82Bhthurs8nPL_Ck3gG13uPhZQ%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, 12:42am UTC](https://discuss.elastic.co/t/sum-of-total-term-frequency-in-one-document/21289/3 "2017-07-06T00:42:33Z")

</div>


