# Terms aggregation ignoring analyzers?

**URL:** <https://discuss.elastic.co/t/terms-aggregation-ignoring-analyzers/130455>\
**Category:** Elasticsearch\
**Created:** [May 3, 2018, 1:12pm UTC](https://discuss.elastic.co/t/terms-aggregation-ignoring-analyzers/130455 "2018-05-03T13:12:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![randomuser](https://avatars.discourse-cdn.com/v4/letter/r/958977/32.png) [@randomuser](https://discuss.elastic.co/u/randomuser)\
**Post date:** [May 3, 2018, 1:12pm UTC](https://discuss.elastic.co/t/terms-aggregation-ignoring-analyzers/130455/1 "2018-05-03T13:12:05Z")

</div>

Hello guys,

I'm trying to run a simple terms aggregation:

```
GET test3/_search
{
    "aggs" : {
        "agg_name" : {
            "terms" : { 
              "field" : "words"
            }
        }
    },
    "size" : 0
}

```

My goal is to get a simple doc\_count for every word (token) within the field words. But I keep getting the raw value of the whole words field.

**For example:**  
_"words" : "This is a sentence"_  
I'm expecting to get separate tokens like _["this", "is", "a", "sentence"]_ and count the occurrences of each token. What I get is _["this is a sentence"]_ for every words field with the doc\_count resulting 1.

I have tried using different analysers and tokenisers, but whichever combination I use, the result is the same, so I'm really confused at the moment, as it seems that tokenisers don't have any effects on the aggregation.

This is my latest (current) index mapping configuration:

```
{
    "order": 0,
    "index_patterns": [
        "words-data-*"
    ],
    "settings": {
        "index": {
            "max_result_window": "200000",
            "refresh_interval": "-1",
            "analysis": {
                "analyzer": {
                    "my_analyzer": {
                        "filter": [
                            "lowercase",
                            "trim",
                            "reverse"
                        ],
                        "type": "custom",
                        "tokenizer": "standard"
                    }
                }
            },
            "number_of_shards": "1",
            "number_of_replicas": "0"
        }
    },
    "mappings": {
        "keywords": {
            "_all": {
                "enabled": false
            },
            "properties": {
                "words": {
                    "ignore_above": 256,
                    "store": true,
                    "eager_global_ordinals": true,
                    "type": "keyword",
                    "fields": {
                        "reverse": {
                            "search_analyzer": "my_analyzer",
                            "analyzer": "my_analyzer",
                            "type": "text"
                        }
                    }
                }
            }
        }
    },
    "aliases": {}
}

```

I would be expecting lots of different tokens, but it looks like there are none. I want the results of a standard tokeniser for the words field when running aggregations.

By the way, any other suggestions for the mapping?

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [May 3, 2018, 3:56pm UTC](https://discuss.elastic.co/t/terms-aggregation-ignoring-analyzers/130455/2 "2018-05-03T15:56:49Z")

</div>

This is your issue:

> [@randomuser](#):
>
> "type": "keyword",

You've configured the `"words"` field as a `keyword` field, which means the text "this is a sentence" will be indexed as single token `this is a sentence`. You'll need to change the type to `text` so that you can assign it an analyzer. Then you'll see tokens like you expect in the Terms agg.

---

<div class="post-metadata">

**Author:** ![randomuser](https://avatars.discourse-cdn.com/v4/letter/r/958977/32.png) [@randomuser](https://discuss.elastic.co/u/randomuser)\
**Post date:** [May 4, 2018, 12:01pm UTC](https://discuss.elastic.co/t/terms-aggregation-ignoring-analyzers/130455/3 "2018-05-04T12:01:00Z")

</div>

Of all the things I've went through, this crossed my mind but didn't even bother trying it. Works like a charm now, thank you!

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [May 4, 2018, 1:14pm UTC](https://discuss.elastic.co/t/terms-aggregation-ignoring-analyzers/130455/4 "2018-05-04T13:14:39Z")

</div>

Happy to help! 🙂

---

<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:** [June 1, 2018, 1:14pm UTC](https://discuss.elastic.co/t/terms-aggregation-ignoring-analyzers/130455/5 "2018-06-01T13:14:40Z")

</div>

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