Fielddata error indexing string fields

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:

      {
        "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:

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

Thanks in advance

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.

Thanks, very helpful to know

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