Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ElasticSearch 5.1 Fielddata is disabled in text field by default [ERROR: trying to use aggregation on field]

Having this field in my mapping

"answer": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },

i try to execute this aggregation

"aggs": {
"answer": {
  "terms": {
    "field": "answer"
  }
},

but i get this error

"type": "illegal_argument_exception",
      "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [answer] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."

Do i have to change my mapping or am i using the wrong aggregation ? (just updated from 2.x to 5.1)

like image 272
Nacho Nieva Avatar asked Jan 05 '17 12:01

Nacho Nieva


1 Answers

You need to aggregate on the keyword sub-field, like this:

"aggs": {
"answer": {
  "terms": {
    "field": "answer.keyword"
  }
},

That will work.

like image 199
Val Avatar answered Oct 15 '22 18:10

Val