# Index text as keyword array leveraging tokenizers and filters

**URL:** https://discuss.elastic.co/t/index-text-as-keyword-array-leveraging-tokenizers-and-filters/237976
**Category:** Elasticsearch
**Created:** [June 21, 2020, 7:47pm UTC](https://discuss.elastic.co/t/index-text-as-keyword-array-leveraging-tokenizers-and-filters/237976 "2020-06-21T19:47:30Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![rsinger86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rsinger86/32/70767_2.png) [@rsinger86](https://discuss.elastic.co/u/rsinger86)
#### Post date: [June 21, 2020, 7:47pm UTC](https://discuss.elastic.co/t/index-text-as-keyword-array-leveraging-tokenizers-and-filters/237976/1 "2020-06-21T19:47:30Z")

</div>

Say I am indexing emails as documents into Elasticsearch, and I'd like to index the email body as an array of [keywords](https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html), in addition to indexing it as an analyzed text field.

My purpose is that I'd like to do term aggregations on the words in the email body field, but I don't want to enable fielddata. Indexing using the keyword datatype (as an array) allows me to have these stored as doc\_values on disk.

For example if I want to index this text:  
_"Greetings user: Welcome to our app! We are hopeful that you will have an enjoyable time!"_

In my application, I could naively convert this text to an array, by breaking on whitespace and lowercasing the elements, so that I index a keyword array that looks like this:  
`["greetings", "user:", "welcome", "to", "our", "app", "we", "are", "hopeful", "that", "you", "will", "have", "an", "enjoyable", "time!']`

But it would be nice if I could use Elasticsearch's built-in tokenizers and filters to remove the stop words, more intelligently break the text into words, and do stemming, so that I index a keyword array like this:  
`["greet", "user", "welcome", "app", "hope", "enjoy", "time']`

Is there anyway I can set up a keyword mapping that leverages the text analyzers in this way? Here is the pseudo mapping that I'm going for:

```
{
  "mappings": {
    "properties": {
      "email_body_words": {
        "type": "keyword",
        "split_text_into_array_of_k_stemmed_tokens_and_remove_stop_words": true
      }
    }
  }
}
```

---

<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 19, 2020, 7:47pm UTC](https://discuss.elastic.co/t/index-text-as-keyword-array-leveraging-tokenizers-and-filters/237976/2 "2020-07-19T19:47:30Z")

</div>

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