默认情况下,ElasticSearch 5.1 Fielddata在文本字段中被禁用[错误:尝试在字段上使用聚合]

Nac*_*eva 7 mapping aggregation elasticsearch

在我的映射中有这个字段

"answer": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
Run Code Online (Sandbox Code Playgroud)

我尝试执行此聚合

"aggs": {
"answer": {
  "terms": {
    "field": "answer"
  }
},
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误

"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."
Run Code Online (Sandbox Code Playgroud)

我是否必须更改映射或使用错误的聚合?(刚刚从2.x更新到5.1)

Val*_*Val 25

您需要在keyword子字段上聚合,如下所示:

"aggs": {
"answer": {
  "terms": {
    "field": "answer.keyword"
  }
},
Run Code Online (Sandbox Code Playgroud)

那可行.