# Performance of keyword vs fielddata

**URL:** https://discuss.elastic.co/t/performance-of-keyword-vs-fielddata/204742
**Category:** Elasticsearch
**Created:** [October 22, 2019, 11:52pm UTC](https://discuss.elastic.co/t/performance-of-keyword-vs-fielddata/204742 "2019-10-22T23:52:37Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![yungnvn](https://avatars.discourse-cdn.com/v4/letter/y/71e660/32.png) [@yungnvn](https://discuss.elastic.co/u/yungnvn)
#### Post date: [October 22, 2019, 11:52pm UTC](https://discuss.elastic.co/t/performance-of-keyword-vs-fielddata/204742/1 "2019-10-22T23:52:37Z")

</div>

Hi,

I had a couple of questions regarding keywords vs fielddata.

I understand if fielddata type for "text" fields are enabled, it is much more performance intensive since it has to store it in the JVM memory itself.

1. How does the keyword perform in comparison to fielddata? Is it also stored in memory?

2. When I run `_cat/fielddata` i'm seeing multiple fields that are returned with a .keyword at the end. The biggest ones are message.keyword. Does this mean that every keyword type is also stored in memory since `_cat/fielddata` is supposed to return how much heap memory is being used?

Here's the top results of what `_cat/fielddata?h=field,size` returns

```auto
message.keyword 1.2mb
message.keyword 1.2mb
message.keyword 668kb
message.keyword 479.5kb
message.keyword 436.7kb
message.keyword 431.9kb
message.keyword 406.1kb
message.keyword 399kb
message.keyword 366.2kb
message.keyword 274.1kb
message.keyword 238.3kb
message.keyword 205.9kb
message.keyword 154.2kb
message.keyword 148.9kb
message.keyword 141.2kb
message.keyword 134.5kb
message.keyword 102.5kb
message.keyword 99.2kb
message.keyword 90.4kb
message.keyword 90.3kb
message.keyword 88kb
host.name.keyword 64.6kb

```

1. Why are .keyword fields being returned in a `_cat/fielddata` API calls?

Thanks

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [October 23, 2019, 1:11am UTC](https://discuss.elastic.co/t/performance-of-keyword-vs-fielddata/204742/2 "2019-10-23T01:11:42Z")

</div>

Fieldata loads data in JVM heap. The first time you want to sort or aggregate, you will load the data in memory.  
Keyword data type uses doc values. Doc values are stored on disk. They are precomputed at index time. Any time you want to sort or aggregate, you will read the data from disk. But remember that segments are immutable. Which means that the OS will cache in its memory the files you are often reading. So at the end of the day, you will have loaded doc values in RAM. And it will be as fast as fielddata but without using the JVM HEAP which has a lot of advantages.

HTH

---

<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: [November 20, 2019, 1:11am UTC](https://discuss.elastic.co/t/performance-of-keyword-vs-fielddata/204742/3 "2019-11-20T01:11:47Z")

</div>

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