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

半世苍凉 提交于 2019-12-07 00:57:31

问题


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)


回答1:


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

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

That will work.




回答2:


In Aggregation, just add keyword to answer.It worked for me. For text fields we need to add keyword. "field": "answer.keyword"




回答3:


Adding to @Val's answer, you can also set the fielddata to true during your mapping itself:

"answer": {
        "type": "text",
        "fielddata": true, <-- add this line
        "fields": {
          "keyword": {
            "type": "keyword",                
            "ignore_above": 256
          }
        }
      },


来源:https://stackoverflow.com/questions/41485058/elasticsearch-5-1-fielddata-is-disabled-in-text-field-by-default-error-trying

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!