Skip to content

Instantly share code, notes, and snippets.

@Hungsiro506
Last active August 3, 2021 08:54
Show Gist options
  • Save Hungsiro506/7821f6307e752c1b34ee072209c05a77 to your computer and use it in GitHub Desktop.
Save Hungsiro506/7821f6307e752c1b34ee072209c05a77 to your computer and use it in GitHub Desktop.

Given a field named eventType with mapping.

"itemType" : {
  "type" : "text",
  "fields" : {
      "keyword" : {
      "type" : "keyword",
      "ignore_above" : 256
      }
  },
  "analyzer" : "folding"
}

I want to get all values of that specific field. When i use bucket-term aggregations
    "aggs" : {
        "values" : {
            "terms" : { "field" : "eventType" }
        }
    }

i get the following exception:

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 [eventType] in order to load field data by uninverting the inverted index. Note that this can use significant memory


And in the ES official docs, there is a note as following.

The field can be Keyword, Numeric, ip, boolean, or binary. By default, you cannot run a terms aggregation on a text field. Use a keyword sub-field instead. Alternatively, you can enable fielddata on the text field to create buckets for the field’s analyzed terms. Enabling fielddata can significantly increase memory usage.
Ref


My questions are:

  1. My setting "keyword" on evenType mapping does not make that field can be seen as a keyword data type on aggregation ? As i know that, fields keyword allow a field can be indexed for multiple purposes.
  2. How can i solve this problem ?.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment