# Elasticsearch Retrieve token\_count standard value from search

**URL:** <https://discuss.elastic.co/t/elasticsearch-retrieve-token-count-standard-value-from-search/211161>\
**Category:** Elasticsearch\
**Created:** [December 9, 2019, 4:59pm UTC](https://discuss.elastic.co/t/elasticsearch-retrieve-token-count-standard-value-from-search/211161 "2019-12-09T16:59:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diogo\_Correia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/diogo_correia/32/59053_2.png) [@Diogo\_Correia](https://discuss.elastic.co/u/Diogo_Correia)\
**Post date:** [December 9, 2019, 4:59pm UTC](https://discuss.elastic.co/t/elasticsearch-retrieve-token-count-standard-value-from-search/211161/1 "2019-12-09T16:59:47Z")

</div>

Hi!

I am trying to add a new field into the ElasticSearch index to analyze and store the number of words a text has.

```
{
"settings": {
    "analysis": {
        "analyzer": {
            "character_analyzer": {
                "type": "custom",
                "tokenizer": "character_tokenizer"
            }
        },
        "tokenizer": {
            "character_tokenizer": {
                "type": "ngram",
                "min_gram": 1,
                "max_gram": 1
            }
        }
    }
},
"mappings": {
    "_doc": {
        "dynamic": "strict",
        "properties": {
            "name": {
                "type": "text",
                        "fields": {
                            "words_count": {
                                "type": "token_count",
                                "analyzer": "standard",
                                "store": true
                            }

```

Performing a query I am able to retrieve the documents which have the total words count I request in query:

```
{   
"size": 1,
"query": {
    "bool" : {
        "must" : {
            "range" : {
                "name.words_count": {
                   "gt": 3
                }
            }
        }
    }
}

```

But I would like to retrieve this value on \_source results. Is it possible? Am I missing something?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 10, 2019, 12:57pm UTC](https://discuss.elastic.co/t/elasticsearch-retrieve-token-count-standard-value-from-search/211161/2 "2019-12-10T12:57:12Z")

</div>

This is not part of the `_source`, as it was not part of the original JSON. You could however retrieve this as a docvalue field or just enable the `store` setting in the mapping and the use `docvalue_fields` or `"docvalue_fields": ["name.length"]` or `"stored_fields": ["name.length"]` in the query to retrieve the value.

--Alex

---

<div class="post-metadata">

**Author:** ![Diogo\_Correia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/diogo_correia/32/59053_2.png) [@Diogo\_Correia](https://discuss.elastic.co/u/Diogo_Correia)\
**Post date:** [December 17, 2019, 2:51pm UTC](https://discuss.elastic.co/t/elasticsearch-retrieve-token-count-standard-value-from-search/211161/3 "2019-12-17T14:51:45Z")

</div>

Thank you Alexander for you answer. It worked as a charm for me.  
I have another related question regarding this if you could help me.

I was trying to understand how much space this new stored field could occupy on elastic search. Is there any way to get this metrics through the elastic search?

---

<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:** [January 14, 2020, 2:51pm UTC](https://discuss.elastic.co/t/elasticsearch-retrieve-token-count-standard-value-from-search/211161/4 "2020-01-14T14:51:47Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
