Elasticsearch5.x版本中對Text類型進行聚合時提示illegal_argument_exception


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."

得到解決
You need to aggregate on the keyword sub-field, like this:
"aggs": {
"answer": {
  "terms": {
    "field": "answer.keyword"
  }
},

開始在網上查詢解決方案時,有的是修改mapping
1.PUT my_index/_mapping/my_type { "properties": { "my_field": { "type": "text", "fielddata": true } } }


或者
2.使用.keyword 推薦
"aggs": { "answer": { "terms": { "field": "answer.keyword" } }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM