# When can keyword field with doc values enabled consume fielddata cache?

**URL:** https://discuss.elastic.co/t/when-can-keyword-field-with-doc-values-enabled-consume-fielddata-cache/127146
**Category:** Elasticsearch
**Created:** [April 6, 2018, 11:08pm UTC](https://discuss.elastic.co/t/when-can-keyword-field-with-doc-values-enabled-consume-fielddata-cache/127146 "2018-04-06T23:08:05Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Ankit\_Malpani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ankit_malpani/32/14566_2.png) [@Ankit\_Malpani](https://discuss.elastic.co/u/Ankit_Malpani)
#### Post date: [April 6, 2018, 11:08pm UTC](https://discuss.elastic.co/t/when-can-keyword-field-with-doc-values-enabled-consume-fielddata-cache/127146/1 "2018-04-06T23:08:05Z")

</div>

ES version - 6.2.3

Sometimes after running an aggregation query on a keyword field enabled with doc\_values, my fielddata cache is still being consumed which was unexpected for me. When can this happen?

eg. here is a mapping of my test index

```
curl localhost:9200/data?pretty
{
  "data" : {
    "aliases" : { },
    "mappings" : {
      "type1" : {
        "properties" : {
          "age" : {
            "type" : "integer"
          },
          "city" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "city_dv" : {
            "type" : "keyword"
          },
          "city_nondv" : {
            "type" : "keyword",
            "doc_values" : false
          },
          "city_text" : {
            "type" : "text"
          },
          "comments" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "month" : {
            "type" : "keyword"
          },
          "name" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "salary" : {
            "type" : "float"
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1523053143368",
        "number_of_shards" : "1",
        "number_of_replicas" : "0",
        "uuid" : "qkzge3m8T0-r2pEcAm3reg",
        "version" : {
          "created" : "6020399"
        },
        "provided_name" : "data"
      }
    }
  }
}

```

Here is the query:

```
curl -H "Content-Type: application/json" http://localhost:9200/data/_search?pretty -d '{
    "aggs" : {
        "city_breakup" : { "terms" : { "field" : "city_dv" } }
    }
  }'

```

Here is a look at cache consumption after the query (it does reset back to 0 after a while but still is seeing the field 'city\_dv' take up fielddata cache expected?

```
curl "localhost:9200/_stats/fielddata?fields=*&pretty"
{
  "_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
  },
  "_all" : {
"primaries" : {
  "fielddata" : {
    "memory_size_in_bytes" : 45128624,
    "evictions" : 0,
    "fields" : {
      "city_dv" : {
        "memory_size_in_bytes" : 45128624
      }
    }
  }
},
"total" : {
  "fielddata" : {
    "memory_size_in_bytes" : 45128624,
    "evictions" : 0,
    "fields" : {
      "city_dv" : {
        "memory_size_in_bytes" : 45128624
      }
    }
  }
}
  },
  "indices" : {
"data" : {
  "primaries" : {
    "fielddata" : {
      "memory_size_in_bytes" : 45128624,
      "evictions" : 0,
      "fields" : {
        "city_dv" : {
          "memory_size_in_bytes" : 45128624
        }
      }
    }
  },
  "total" : {
    "fielddata" : {
      "memory_size_in_bytes" : 45128624,
      "evictions" : 0,
      "fields" : {
        "city_dv" : {
          "memory_size_in_bytes" : 45128624
        }
      }
    }
  }
}
  }
}
```

---

<div class="post-metadata">

### Author: ![hhliu](https://avatars.discourse-cdn.com/v4/letter/h/e0b2c6/32.png) [@hhliu](https://discuss.elastic.co/u/hhliu)
#### Post date: [April 23, 2018, 3:00am UTC](https://discuss.elastic.co/t/when-can-keyword-field-with-doc-values-enabled-consume-fielddata-cache/127146/2 "2018-04-23T03:00:10Z")

</div>

I encounter the same problem.

---

<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: [May 21, 2018, 3:00am UTC](https://discuss.elastic.co/t/when-can-keyword-field-with-doc-values-enabled-consume-fielddata-cache/127146/3 "2018-05-21T03:00:14Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [August 10, 2018, 9:32am UTC](https://discuss.elastic.co/t/when-can-keyword-field-with-doc-values-enabled-consume-fielddata-cache/127146/4 "2018-08-10T09:32:05Z")

</div>

The `fielddata` settings you might pick for a field are only one of several potential contributors to the overall internal fielddata accounting that is reported.

Even if you don't select to use fielddata in your mapping certain actions may cause other field-related structures to be loaded into memory e.g. a `terms` aggregation may trigger the use of a global ordinals map under the covers to service the request. These costs fall under the umbrella of fielddata-related stats
