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

时间:2017-01-05 12:24:54

标签: elasticsearch mapping aggregation

在我的映射中使用此字段

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

我尝试执行此聚合

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

但我收到此错误

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

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

3 个答案:

答案 0 :(得分:23)

您需要在window.clipsToBounds = YES子字段上汇总,如下所示:

keyword

这将有效。

答案 1 :(得分:1)

添加到@ Val的答案,您还可以在映射过程中将fielddata设置为true:

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

答案 2 :(得分:1)

在聚合中,只需添加关键字即可回答。它对我有用。对于文本字段,我们需要添加关键字。     &#34; field&#34;:&#34; answer.keyword&#34;