# Fielddata error indexing string fields

**URL:** <https://discuss.elastic.co/t/fielddata-error-indexing-string-fields/289105>\
**Category:** Elasticsearch\
**Created:** [November 12, 2021, 11:24pm UTC](https://discuss.elastic.co/t/fielddata-error-indexing-string-fields/289105 "2021-11-12T23:24:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamtheschmitzer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iamtheschmitzer/32/96988_2.png) [@iamtheschmitzer](https://discuss.elastic.co/u/iamtheschmitzer)\
**Post date:** [November 12, 2021, 11:24pm UTC](https://discuss.elastic.co/t/fielddata-error-indexing-string-fields/289105/1 "2021-11-12T23:24:24Z")

</div>

In notes of Part 5 of crash course I see

> By default, every string gets mapped twice as a text field and as a keyword multi-field. Each field type is primed for different types of requests.

However, when I try to aggregate by a string field (with a limited set of single-word values) I get an error:

```auto
      {
        "type" : "illegal_argument_exception",
        "reason" : "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [measure] in order to load field data by uninverting the inverted index. Note that this can use significant memory."
      }

```

What does this error mean and what is the resolution? For reference my query looks like this:

```auto
GET index_name/_search
{
  "aggs": {
    "maxtime by measure": {
      "terms": {
        "field": "measure"
        }
      },
      "aggs": {
        "max": {
          "field": "time"
        }
      }
  },
  "size": 0
}

```

Thanks in advance

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [November 15, 2021, 11:14pm UTC](https://discuss.elastic.co/t/fielddata-error-indexing-string-fields/289105/2 "2021-11-15T23:14:11Z")

</div>

When you index a string and don't provide a mapping, `measure` will be indexed as a `text` field, and `measure.keyword` as a keyword field. So you need to run your terms aggregation on `measure.keyword` field.

---

<div class="post-metadata">

**Author:** ![iamtheschmitzer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/iamtheschmitzer/32/96988_2.png) [@iamtheschmitzer](https://discuss.elastic.co/u/iamtheschmitzer)\
**Post date:** [November 16, 2021, 4:18pm UTC](https://discuss.elastic.co/t/fielddata-error-indexing-string-fields/289105/3 "2021-11-16T16:18:25Z")

</div>

Thanks, very helpful to know

---

<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:** [December 14, 2021, 4:18pm UTC](https://discuss.elastic.co/t/fielddata-error-indexing-string-fields/289105/4 "2021-12-14T16:18:26Z")

</div>

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