【问题标题】:ElasticSearch 5.1 Fielddata is disabled in text field by default [ERROR: trying to use aggregation on field]默认情况下,ElasticSearch 5.1 Fielddata 在文本字段中被禁用 [错误:尝试在字段上使用聚合]
【发布时间】:2017-05-19 23:56:44
【问题描述】:

在我的映射中有这个字段

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

【问题讨论】:

    标签: elasticsearch mapping aggregation


    【解决方案1】:

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

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

    这会起作用的。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        除了@Val 的回答,您还可以在映射过程中将fielddata 设置为true:

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

        【讨论】:

        • 我不确定keyword type 是否接受任何fielddata 设置,就像text 类型一样。
        • 根据异常 (Set fielddata=true on [answer]),我认为问题出在所提供映射中的 answer
        • 那是因为他在answer 上进行了聚合,但他最好还是在answer.keyword 上进行聚合,因为他有那个字段。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-02
        • 2023-03-30
        • 1970-01-01
        • 2018-03-08
        相关资源
        最近更新 更多